0

有很多关于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 文件上设置属性,则此视图将位于其他所有内容之上。

4

2 回答 2

0

您永远不应该release直接发送到属性!内存管理在 setter 方法中为您完成!

代替:

[self.someProperty release];

写:

self.someProperty = nil;

通常您在dealloc方法中执行此操作。

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

编辑

添加自动释放:

self.timeline = [[[TimelineViewController alloc] initWithNibName:@"Timeline" bundle:[NSBundle mainBundle]] autorelease];
于 2011-06-13T16:52:36.517 回答
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;  
于 2011-06-13T17:13:53.510 回答