UINavigationController不工作(pushViewController忽略视图)

时间:2011-06-13 16:20:36

标签: iphone objective-c uinavigationcontroller pushviewcontroller

关于UINavigationController有很多问题。我修改我的代码以遵循Apple示例,但pushViewController方法不起作用:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

[window addSubview:navController.view];

[window makeKeyAndVisible];

LoginController *login = (LoginController*)[self.navController.viewControllers objectAtIndex:0];

if([login already_validated] == TRUE) {
    self.timeline = [[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]];

    [navController pushViewController:timeline animated:YES];

    [self.timeline release];
}

return YES;     

视图在行中正确加载:

self.timeline = [[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]];

...但

[navController pushViewController:timeline animated:YES];

不显示视图。我已经检查过,navController不是空的。

有什么想法吗?

最佳!

卢卡斯。


固定!!

问题在于MainWindow.xib

不要在窗口类上设置rootViewController

如果在XIB文件上设置属性,则此视图将位于其他所有内容之上。

2 个答案:

答案 0 :(得分:0)

您不应该直接向房产发送release!内存管理是在你的setter方法中完成的!

而不是:

[self.someProperty release];

写:

self.someProperty = nil;

通常,您可以使用dealloc方法执行此操作。

在您的情况下,只需删除行[self.timeline release];或根本不使用属性。

修改

添加自动释放:

self.timeline = [[[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]] autorelease];

答案 1 :(得分:0)

试试这个......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


[window addSubview:navController.view];


[window makeKeyAndVisible];


LoginController *login = (LoginController*)[navController.viewControllers objectAtIndex:0];//here remove self


if([login already_validated] == TRUE) {

    self.timeline = [[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:nil];//remove the nsbundle mainbundle


    [navController pushViewController:self.timeline animated:YES];//here u have to use with self.timeline

    [self.timeline release];

}

return YES;