【问题标题】:UINavigationController not working (pushViewController ignores the view)UINavigationController 不工作(pushViewController 忽略视图)
【发布时间】:2011-09-14 01:28:58
【问题描述】:

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

【问题讨论】:

    标签: iphone objective-c uinavigationcontroller pushviewcontroller


    【解决方案1】:

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

    代替:

    [self.someProperty release];
    

    写:

    self.someProperty = nil;
    

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

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

    编辑

    添加自动释放:

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

    【讨论】:

    • 现在写的有点乱,但是如果是retain属性,其实他得释放self.timeline里面的对象,因为他之前是在一行中分配的。
    • 谢谢贡萨洛。实际上我删除了该属性:)
    【解决方案2】:

    试试这个..

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

    【讨论】:

    • 我已尝试删除并添加您提到的内容。没有运气:(。
    • 检查 TimelineViewController nib 或 Timeline nib u have.and remove nsbundle mainbundle to nil
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 2011-04-02
    • 2011-09-29
    相关资源
    最近更新 更多