0

我在 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 的应用程序午餐,但是如果我将 viewController 设置为 rootviewController,我的导航控制器不会推送导航,反之亦然,如果将我的导航控制器设置为根,则应用程序不会从菜单或主视图加载控制器 。

4

1 回答 1

1

为什么要将 Poemsview 创建为 Navigation Controller 的 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.

于 2012-12-16T18:19:09.827 回答