您的位置:首页 > 移动开发 > IOS开发

关于 IOS 开发中遇到的 读取 cell xib 文件时导致死机的问题。

2013-03-29 00:07 645 查看
下面这句话看上去没有什么问题,但是偏偏在这个地方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 关联。
直接关联到对应的属性上。

这样就可以了。然后重新编译运行下。问题解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: