uiviewControllerにChildViewControllerとして追加されるナビゲーションコントローラにテーブルビューを追加する方法

StackOverflow https://stackoverflow.com//questions/21052870

質問

uiviewControllerとしてuiviewControllerとして追加されたUIViewControllerが追加されています。

exampleView = [[UIViewController alloc] init];

//Setting the frame of the child UIViewController

CGRect frame = self.view.frame;
frame.origin.y = frame.origin.y + 83.0;
frame.size.height = 200.0;
exampleView.view.frame = frame;

[self addChildViewController:exampleView];
[self.view addSubview:exampleView.view];
[exampleView didMoveToParentViewController:self];
.

その後、uinavigationControllerをChildviewController

に追加します。
//Adding navigation controller to the child view.

UINavigationController *nav = [[UINavigationController alloc]     initWithRootViewController:exampleView];
nav.navigationBar.translucent = NO;
[exampleView.view addSubview:nav.view];
exampleView.title = @"mynameasdasd";
.

注:ナビゲーションコントローラがビューの中央にある(画面全体のサイズを占有していない)必要があるため、これを行います。

このNavigationControllerにTableViewを追加し、通常のナビゲーションを続行します。どうやってこれを行うべきです。このナビゲーションコントローラにTableViewを追加できません。

役に立ちましたか?

解決

initWithRootViewControllerに渡されているパラメータは間違っています。それはUITableViewController

のビューであるべきです
UITableViewController *tvc = [[UITableViewController alloc] init];
tvc.delegate = <Put your UITableViewDelegate here>
tvc.datasource = <Put your UITableViewDatasource here>
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tvc];
nav.navigationBar.translucent = NO;
[exampleView.view addSubview:nav.view];
exampleView.title = @"mynameasdasd";
.

他のヒント

You cannot add a table view to a navigation controller. You can only add a view controller containing a table view to a navigation controller.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top