UINavigationController 不工作(pushViewController 忽略视图)

发布于 2024-11-15 05:39:35 字数 1187 浏览 2 评论 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 文件上设置该属性,则该视图将位于其他所有内容之上。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏花。依旧 2024-11-22 05:39:35

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

而不是:

[self.someProperty release];

write:

self.someProperty = nil;

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

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

编辑

添加自动释放:

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

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];
静待花开 2024-11-22 05:39:35

试试这个..

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

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;  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文