"Auto Layout is still required" error when adding subview to UITableView on iOS 7 only

I have a container that uploads UITableViewController

. Initially, there is no data in the table, so I am showing an empty view. This is how I do it in ViewDidLoad

:

emptyView = new UIView ();
emptyView.BackgroundColor = UIColor.Gray;
// works on iOS 8 but has to be removed on iOS 7
emptyView.TranslatesAutoresizingMaskIntoConstraints = false;

var views = NSDictionary.FromObjectsAndKeys(
    new object[] { emptyView },
    new object[] { "emptyView" }
);

View.AddSubview (emptyView);
this.TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;

View.AddConstraints(NSLayoutConstraint.FromVisualFormat ("V:|-0-[emptyView]-0-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, views));
View.AddConstraints(NSLayoutConstraint.FromVisualFormat ("H:|-0-[emptyView]-0-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, views));

      

Now the problem is where I turn off the autosize mask. On iOS 7.1 (device and simulator) I get the following error:

NSInternalInconsistencyException Cause: Auto-layout required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.

If I comment TranslatesAutoresizingMaskIntoConstraints

, everything will be fine. The same code works unchanged in iOS 8. I only remove the autoresist mask on my view, not the whole UITableView

. Adding a view to the table header leads to the same problem.

How can I fix the auto-layout issue? Although the code is in C #, you can always provide solutions from the Objective C world, because the concepts are the same.

+3


source to share


1 answer


I moved away from auto layout and I no longer use it for emptyView

.

emptyView = new UIView (new RectangleF(0, 0, this.View.Bounds.Size.Width, this.View.Bounds.Size.Height));
emptyView.BackgroundColor = UIColor.White;
emptyView.AutoresizingMask = UIViewAutoresizing.All;

      



It works now, but I don't know if it is intended not to use auto-layout. Perhaps a better answer could be given, which I could mark as accepted.

0


source







All Articles