【问题标题】:iOS instance variable gets "NULLED" for unknown reasoniOS 实例变量因未知原因被“NULLED”
【发布时间】:2013-04-30 09:16:41
【问题描述】:

我有一个看起来像这样的实例变量:

@property (strong, nonatomic) Post *post;

我在一个自定义的 init 方法中设置它,如下所示:

- (id)initWithPageType:(int)pageType andPost:(Post *)post
{
    self = [super initWithNibName:@"StreamViewController" bundle:nil];
    if (self) {
        // Custom initialization
        self.post = post;
        self.pageType  = pageType;
    }
    return self;
}

在这种情况下它永远不会是 NULL。我也有一个 NSFetchedResultsController 使用以下委托方法:

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
   atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
  newIndexPath:(NSIndexPath *)newIndexPath
{
    [...]
    // Here self.post == nil for some reason...
    [...]

有人知道为什么会这样吗?

【问题讨论】:

  • 我认为 post 对象的所有权不知何故过期了,这使它为零。

标签: ios xcode cocoa-touch nsfetchedresultscontroller


【解决方案1】:

编写自己的 setter,然后在 setter 中的语句上放置断点。现在你就知道是什么代码设置了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 2016-02-02
    • 2013-04-09
    • 1970-01-01
    相关资源
    最近更新 更多