2014-10-14 5 views
0

Я хочу создать представление контейнера, которое имеет некоторые виды на нем. Мне удалось заставить эту работу работать с Auto Layout. Теперь я хочу разместить этот контейнер в UINavigationController. Я сделал это в конструкторе IOS, но следующий код больше не работает (работает без навигационного контроллера):Добавить представление контейнера в контроллер навигации

HalfTableViewController testController1 = new HalfTableViewController(); 
this.AddChildViewController (testController1); 
testController1.View.Frame = View.Bounds; 
this.View.AddSubview (testController1.View); 

Это в C#, но это не имеет значения, если вы не знакомы с ним. Я хочу знать, как я могу использовать представление контроллера навигации в виде контейнера, на котором я могу добавить свои представления. В настоящее время я вижу панель навигации, но это черный экран. Я пробовал несколько вещей, но я не знаю, как я могу заставить это работать. Ваше решение может быть, конечно, в Objective-C.

Edit:

Я пробовал без AutoLayout и вида таблицы показывает вверх. Теперь я хочу знать, что я делаю неправильно. Вот мой код автомата:

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()); 

Что мне не хватает?

ответ

0

Это, кажется, делает этот трюк:

//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.Bottom, NSLayoutRelation.Equal, BottomLayoutGuide, NSLayoutAttribute.Top, 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 (tv2.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1, 0)); 
constraints.Add (NSLayoutConstraint.Create (tv2.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, BottomLayoutGuide, NSLayoutAttribute.Top, 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, tv1.View, NSLayoutAttribute.Width, 1, 0)); 

constraints.Add (NSLayoutConstraint.Create (tv3.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1, 0)); 
constraints.Add (NSLayoutConstraint.Create (tv3.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, BottomLayoutGuide, NSLayoutAttribute.Top, 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.Width, NSLayoutRelation.Equal, tv1.View, NSLayoutAttribute.Width, 1, 0)); 
0

В принципе, вы должны знать концепцию контроллера модели.

  1. Здесь контроллер является навигационным контроллером, который содержит представления, которые мы будем использовать и из.
  2. модель данные
  3. вид диспетчера имеет вид сверху.

Код:

//Create a container view. 
From above concept the below is view 
TestViewController *testview = [[TestviewCopntroller alloc]init]; 
//set some properties 

//the below is data 
testview.somearray = array; 
testview.somedictionary = dictionary; 

//and this is navigation controller 
UINavigationController *nav = [[UInavigationController alloc]initwithrootviewcontroller:testview]; 

//if you want this as root view then 
appdelegate.window.rootviewcontroller = nav; 

//if you want to present this view 
[self presentviewcontroller:nav animated:YES]; 

//if you want to push 
[self.navigationcontroller pushviewcontroller:testview animated:YES]; 
+0

Я знаю концепцию MVC, но это не моя проблема. Я не хочу здесь останавливаться. Я хочу добавить дочерний вид к моему контроллеру навигации (как это должно быть «UIContainerView»). Но я всегда получаю черный экран. – testing

+0

см. U не может добавить subview в контроллер навигации. Есть контроллер представления, который является дочерним элементом контроллера навигации, и вы можете добавить вид контейнера в контроллер child view.navigation - это то, что мы видим с высотой 45 или 60.why do u хотите добавить uicontainerview в контроллер навигации. – iOSdev

+0

Я хочу иметь расширенный 'UISplitViewController'. Я хочу разместить три вида стола рядом. Контроллер разделенного представления может быть только корневым представлением все время. Контейнер может быть решением моей проблемы (с разными взглядами на нее). «UINavigationController» следует использовать для навигации. Или у вас есть другая идея? – testing

Смежные вопросы