J Nelson J Nelson - 1 year ago 122
iOS Question

TableViewController doesn't fill container after cells are added

I'm using Xamarin iOS, so this is in C#...

I have a

with dynamic cells -- one for a Title and N number of cells which the user can add or remove. Below the table view is a footer with a couple buttons. When the Add button is touched, it navigates to an editor for the new item. When it returns from the editor, suddenly the table view isn't filling its container, and the background color of the parent view is seen (Background of the
is default ios grey for Grouped
style. Parent background is white).

Screenshot Before navigation

Screenshot After navigation

To make it even more bizarre, this doesn't show up in the iOS simulator -- only on an actual iPad. Furthermore, it resolves itself if LayoutSubviews is called again (e.g. change orientation to portrait). We use the same container and general design pattern all over the place with no problems. This is the first View that has shown a problem.

Here are the seemingly relevant bits of code:

In the parent view that contains the

public override void ViewDidLoad()

_propertyView = new BackNotifyingUINavigationController(this); //This navigation controller hosts the table view
_propertyView.View.Frame = PropertyContainer.Bounds;
_propertyView.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

//Some unrelated views...

//Some MvvmCross binding stuff...

In the table view:

public override void ViewDidLoad()

_tableSource = new TableSource(TableView); //Custom MvxTableViewSource. Seemingly not overriding anything relevant
_tableSource.UseAnimations = true;
_tableSource.DeselectAutomatically = true;
_tableSource.ReloadOnAllItemsSourceSets = true;

TableView.AlwaysBounceVertical = false;
TableView.TableHeaderView = new UIView(new CoreGraphics.CGRect(0, 0, TableView.Bounds.Width, 10.0f));
TableView.Source = _tableSource;
TableView.SetEditing(true, false); //Always in editing mode

_doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done);
NavigationItem.RightBarButtonItem = _doneButton;

//Some MvvmCross binding stuff...

Edit: This actually happens on both a Push or a Pop on the UINavigationController, only when the keyboard is open.

Answer Source

Finally found a workaround that seems to do the trick, but it feels like a big hack.

In the view controller that owns the UINavigationController...

 public override void ViewDidLayoutSubviews()

        if (_propertyView.TopViewController != null)
            _propertyView.TopViewController.View.Frame = _propertyView.View.Frame;

Of course this is only appropriate if you want the ViewController to take up the UINavigationController's full frame.

Seems like there should be a better way to handle this...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download