I want to create a container view which has some views on it. I managed to get this working with Auto Layout. Now I want to place this container in a UINavigationController
. I did this in the iOS Designer but the following code doesn't work anymore (it works without navigation controller):
HalfTableViewController testController1 = new HalfTableViewController ();
this.AddChildViewController (testController1);
testController1.View.Frame = View.Bounds;
this.View.AddSubview (testController1.View);
It's in C# but it shouldn't matter if you are not familiar with it. I want to know how I can use the view of the navigation controller as container view on which I can add my views. Currently, I see the navigation bar but the view is a black screen. I tried a few things but I don't know how can I get this working. Your solution can be of course in Objective-C.
Edit:
I tried it without AutoLayout and the table views are showing up. Now I want to know what I'm doing wrong. Here is my Auto Layout code:
View.TranslatesAutoresizingMaskIntoConstraints = false;
tv1.View.TranslatesAutoresizingMaskIntoConstraints = false;
tv2.View.TranslatesAutoresizingMaskIntoConstraints = false;
tv3.View.TranslatesAutoresizingMaskIntoConstraints = false;
var constraints = new List<NSLayoutConstraint> ();
constraints.Add (NSLayoutConstraint.Create (tv1.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv1.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv1.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, tv2.View, NSLayoutAttribute.Left, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv1.View, NSLayoutAttribute.Width, NSLayoutRelation.Equal, tv2.View, NSLayoutAttribute.Width, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv1.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv2.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv2.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, tv1.View, NSLayoutAttribute.Right, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv2.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, tv3.View, NSLayoutAttribute.Left, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv2.View, NSLayoutAttribute.Width, NSLayoutRelation.Equal, tv3.View, NSLayoutAttribute.Width, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv2.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv3.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv3.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, tv2.View, NSLayoutAttribute.Right, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv3.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0));
constraints.Add (NSLayoutConstraint.Create (tv3.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
View.AddConstraints (constraints.ToArray ());
What I'm missing?