下面这句话看上去没有什么问题,但是偏偏在这个地方APP crash了。
cell = [[[NSBundlemainBundle] loadNibNamed:CellIdentifierowner:selfoptions:nil]lastObject];
在google.ca,搜索了下: loadNibNamed crash . 得到了这样的一条关键信息:
http://stackoverflow.com/questions/5479684/crash-on-nsbundle-mainbundle-loadnibnamedowneroptions
这里面的一条关键的回复:
The problem is that you connected the labels to the File's Owner, but when you call loadNibNamed..., you pass nil as the file's owner. You should connect the labels to the cell object in the nib. initWithStyle: will not be called when loading from a nib. Nib loading uses initWithCoder: to initialize the object and calls awakeFromNib after the nib is loaded.
事实上是由于我之前的误操作:把所有的view 都关联到了 file's ower. 然后通过 file's ower 关联到对应的 IBOutlet 属性。这样做法是有问题的:
当调用了 loadNibNamed ,其中就有个参数, owner:self 这样将直接导致这个 self 与 xib 的 file's owner 不是同一个概念的。所以将直接导致死机。
正确的做法应该是这样:
取消所有xib与file's owner 关联。
直接关联到对应的属性上。
这样就可以了。然后重新编译运行下。问题解决。