开发者

UINavigationController not working (pushViewController ignores the view)

there are a lot of questions regarding UINavigationController. I modify my code to follow Apple examples, but the pushViewController method is not working:

- (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.time开发者_如何转开发line release];
}

return YES;     

the view is loaded correctly in the line:

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

...but

[navController pushViewController:timeline animated:YES];

does not present the view. I've checked and navController is not null.

Any ideas?

Best!

Lucas.


FIXED!!

The problem resides on the MainWindow.xib.

Do NOT set the rootViewController on the window class!

If you set the attribute on the XIB file, this view will be on top of everything else.


You should never send a release to a property directly! Memory management is done in the setter method for you!

instead of:

[self.someProperty release];

write:

self.someProperty = nil;

Normally you do this in the dealloc method.

In your case simply remove the line [self.timeline release]; or don't use a property at all.

EDIT:

add an autorelease:

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


Try out this one..

- (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;  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜