【问题标题】:Obj-c initWithCoder seems to crash NavigationControllerObj-c initWithCoder 似乎使 NavigationController 崩溃
【发布时间】:2011-08-30 22:04:08
【问题描述】:

有谁知道我为什么添加...

-(id) initWithCoder: (NSCoder *) decoder {

    OutputDataMutableArray = [[decoder decodeObjectForKey:@"RootViewControllerPostArray"] retain];

    return self;

}

对于我的 RootViewController,它不会使用 didSelectRowAtIndexPath 方法从表格单元格推送新视图。这是它似乎坚持的路线......

[[self navigationController] pushViewController:postController animated:YES]; 

我没有收到错误消息,它似乎只是跳过它。除非我把 initWithCoder 拿出来,它工作正常。

任何见解都会被应用。

克里斯

【问题讨论】:

    标签: objective-c uitableview archive


    【解决方案1】:

    你没有调用-initWithCoder:的超类实现。

    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
    
        if(self)
        {
            OutputDataMutableArray = [[decoder decodeObjectForKey:@"RootViewControllerPostArray"] retain];
        }
    
        return self;
    }
    

    【讨论】:

    • “to my RootViewController”似乎暗示该类继承自 UIViewController,不是吗?
    • 这种情况下的安全假设:)
    【解决方案2】:

    检查日志并查找引发的异常导致您的代码过早终止。或者在NSExceptionraise 上设置一个休息时间。

    顺便说一句,您需要在initWithCoder 中致电[super init]

    【讨论】:

      猜你喜欢
      • 2015-07-13
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多