【发布时间】:2014-02-21 09:01:27
【问题描述】:
抱歉这个愚蠢的问题。这是我第一次使用 ARC,我有点困惑。
我声明我的财产为强:
@property (nonatomic, strong) NSMutableArray *dataArray;
我在初始化时用一些测试数据填充它:
- (id)initWithWindowNibName:(NSString *)windowNibName {
self = [super initWithWindowNibName:windowNibName];
if (self) {
self.dataArray = [[NSMutableArray alloc] init];
[self.dataArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"Name", @"First name", @"Set", @"First set", @"Editiion", @"First edition", nil]];
[self.dataArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"Name", @"Second name", @"Set", @"Second set", @"Editiion", @"Second edition", nil]];
[self.dataArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"Name", @"Third name", @"Set", @"Third set", @"Editiion", @"Third edition", nil]];
}
return self;
我来用的时候self.dataArray就是nil
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return self.dataArray.count;
}
我做错了什么,我以为这个属性会在我的对象的生命周期内保留?
【问题讨论】:
-
你确定 initWithWindowNibName 被调用并且 [super initWithWindowNibName:windowNibName] 不返回 nil 吗?
-
你的init被调用了吗?好像不是。也许将代码移动到 awakeFromNib 或任何适当的地方,具体取决于您要继承的类。
-
是的,在 init 中放一个断点。
-
我正在继承 NSWindowController
-
当单步执行初始化时,self.array 在返回时计数为 3
标签: objective-c macos automatic-ref-counting