推送视图不从基于单一视图的应用程序推送UIViewController

时间:2012-05-04 16:52:23

标签: iphone uiviewcontroller uinavigationcontroller

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

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

self.navigationController是null。所以我试图为init分配一个类型为Navigation Controller的局部变量,并且该变量也能够为非null(某些十六进制值),但仍然无法推送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;  

这里是否应对导航控制器进行一些更改?
有什么建议吗?

1 个答案:

答案 0 :(得分: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; 
}