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 文件上设置该属性,则该视图将位于其他所有内容之上。
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.timeline 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您永远不应该直接向属性发送
release
!内存管理是在setter方法中为你完成的!而不是:
write:
通常您可以在
dealloc
方法中执行此操作。在您的情况下,只需删除行
[self.timeline release];
或根本不使用属性。编辑:
添加自动释放:
You should never send a
release
to a property directly! Memory management is done in the setter method for you!instead of:
write:
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:
试试这个..
Try out this one..