我在appDelegate中创建了一个自定义导航控制器:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
poemsView = [[[PoemsViewController alloc]initWithNibName:@"PoemsViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:poemsView] autorelease];
self.navigationController.navigationBarHidden = YES;
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
所以问题是我需要来自viewController的app午餐,但是如果我将viewController设置为rootviewController,我的导航控制器不会推送导航,反之亦然,如果将我的导航控制器设置为root,app不会从菜单加载或主视图控制器。
答案 0 :(得分:1)
为什么要将Poemsview创建为导航控制器的rootviewcontroller?
如果您想首先加载ViewController,请使用以下代码。
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
poemsView = [[[PoemsViewController alloc]initWithNibName:@"PoemsViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];
self.navigationController.navigationBarHidden = YES;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
您可以将另一个导航控制器创建为Sub-class of Viewcontroller.
在你的诗歌按钮动作中添加以下内容:
// Create a regular view controller.
PoemViewController *modalViewController = [[[PoemViewController alloc] initWithNibName:@"PoemViewController" bundle:nil] autorelease];
// Create a navigation controller containing the view controller.
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
// Present the navigation controller as a modal view controller on top of an existing navigation controller
[self presentModalViewController:secondNavigationController animated:YES];
现在,您可以从tableview DidselectRowAtindexpath
。