2

我选择项目模板作为“单一视图”。我试图在按钮单击上推送详细视图(UIViewController)。按钮操作正在正确触发并执行代码 [self navigatingController] 推送......我的代码是作为:

MapDetailViewController *mapDetailViewController = [[MapDetailViewController alloc] init];
    [self.navigationController pushViewController:mapDetailViewController animated:YES];
    NSLog(@"self.navigation is as %@",self.navigationController);  

self.navigationController 为空。所以我尝试分配初始化导航控制器类型的局部变量,并且该变量能够为非空(一些十六进制值),但我仍然无法推送 mapDetailView。
我在想的是我选择了错误的模板(基于视图)。我应该选择基于导航的(主细节)。下面自动生成的代码是应用程序委托的:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;  

导航控制器是否应该在此处进行一些更改?
有什么建议吗?

4

1 回答 1

5

您的问题是您甚至没有导航控制器来进行推送。将您的代码更改为:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    return YES; 
}
于 2012-05-04T16:59:02.687 回答