locked
Dynamically resizing elements at runtime RRS feed

  • Question

  • User176280 posted

    I have a TableView as part of a Autolayout Storyboard that is constrained. This tableview needs to be resized to fit its content that is loaded at runtime.

    I am updating the Frame size of the TableView in the overridden ViewDidAppear method as below.

            public override void ViewDidAppear(bool animated)
            {
                base.ViewDidAppear(animated);
    
                //Autosize the booking table to the content
                UpcomingBookingsTableView.Frame = new CGRect(UpcomingBookingsTableView.Frame.X, 
                                                        UpcomingBookingsTableView.Frame.Y, 
                                                        UpcomingBookingsTableView.Frame.Width, 
                                                        UpcomingBookingsTableView.ContentSize.Height);
            }
    

    The problem I have is two fold.

    1 - When simulator rotates the height of the TableView reverts to the original height from the storyboard and does not respect the new value from the ViewDidAppear method

    2 - When the TableView resizes the content below it does not move with it even though there are constraints set that it should appear offset from the bottom of the table view.

    Any idea how I can resolved these problems?

    Tuesday, March 29, 2016 9:37 AM

Answers

  • User176280 posted

    I have resolved this by binding to the Constraint Height to the number of rows in the collection and used a Value Converter to give me the actual height.

                set.Bind(BookingsTableHeight).For("Constant")
                        .To(vm => vm.UpcomingBookingsViewModel.UpcomingBookings.Count)
                        .WithConversion("UpcomingBookingsToTableHeight");
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 29, 2016 10:36 AM

All replies

  • User176280 posted

    I have resolved this by binding to the Constraint Height to the number of rows in the collection and used a Value Converter to give me the actual height.

                set.Bind(BookingsTableHeight).For("Constant")
                        .To(vm => vm.UpcomingBookingsViewModel.UpcomingBookings.Count)
                        .WithConversion("UpcomingBookingsToTableHeight");
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 29, 2016 10:36 AM
  • User203164 posted

    Hi, I'm getting the same issue as (2) in your original post, is there any chance you could elaborate on how you fixed it?

    Currently I have a CollectionView that's height is defined at runtime, however a label that should be 15dpi below is not moving with the size of the CollectionView

    Thanks

    Tuesday, August 16, 2016 4:25 PM