MyItemCell是一个XIB文件(MyItemCell.xib),包含2个UIImageVIEw和一个UIbutton(每个项目都有一个标签)
这是我的代码:
在我的vIEwController中
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{ return [VIEwHelper loadCustomCellWithNibname:@"MyItemCell" owner:self];}
以及从NIB加载Custom单元格的方法
+ (UItableVIEwCell *) loadCustomCellFromNib:(Nsstring *)nibname owner:(ID)owner{ UItableVIEwCell *cell = nil; NSArray *nibObjects = [[NSBundle mainBundle] loadNibnamed:nibname owner:owner options:nil]; if([nibObjects count] > 0 ) { cell = [nibObjects objectAtIndex:0]; } else { NSLog(@"Failed to load %@ XIB file!",nibname); } return cell;}
在所有测试中一切正常.但是我收到了一些我无法重现的用户崩溃.
这是崩溃:
NSInternalinconsistencyExceptionCould not load NIB in bundle: 'NSBundle </var/mobile/Applications/7A24cE79-131F-523F-4C00-23B523ARG123/MyApp.app> (loaded)' with name 'MyItemCell'
堆栈跟踪:
0 CoreFoundation 0x39b432a3 __exceptionPreprocess + 163 + 1621 libobjc.A.dylib 0x33a3297f objc_exception_throw + 31 + 302 CoreFoundation 0x39b431c5 -[NSException initWithCoder:] + 13 UIKit 0x32e12491 -[UINib instantiateWithOwner:options:] + 1637 + 16364 UIKit 0x32e1a1d7 -[NSBundle(UINSBundleAdditions) loadNibnamed:owner:options:] + 139 + 1385 MyApp 0x00047ded +[VIEwHelper loadCustomCellFromNib:owner:] (VIEwHelper.m:349)6 MyApp 0x00034003 -[BuildVIEwController tableVIEw:cellForRowAtIndexPath:] (BuildVIEwController.m:2432)7 UIKit 0x32cc0545 -[UItableVIEw(UItableVIEwInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 413 + 4128 UIKit 0x32ca530b -[UItableVIEw(_UItableVIEwPrivate) _updateVisibleCellsNow:] + 1311 + 13109 UIKit 0x32cbc7c7 -[UItableVIEw layoutSubvIEws] + 207 + 20610 UIKit 0x32c78803 -[UIVIEw(CALayerDelegate) layoutSublayersOfLayer:] + 259 + 258
问题是我无法重现这次崩溃.
什么可能导致崩溃?或者任何避免这种错误的解决方案?
非常感谢您的帮助
编辑:
只是为了澄清更多,这对我正在进行的任何测试都非常好.对于1个用户,这次崩溃只出现了一次,所以问题不在于代码.我只是在非常具体的情况下搜索可能导致崩溃的原因.谢谢
解决方法 要从NIB文件创建自定义单元格,请尝试此 *** 作- (voID)vIEwDIDLoad{ [tableVIEw registerNib:[UINib nibWithNibname:CellIDentifIEr bundle:nil] forCellReuseIDentifIEr:CellIDentifIEr];}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = (MyCell*)[tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; ...... return cell;}
CellIDentifIEr是NIB文件的名称,也用作单元标识符.
总结以上是内存溢出为你收集整理的ios – UITableView从NIB文件加载自定义单元格抛出NSInternalInconsistencyException全部内容,希望文章能够帮你解决ios – UITableView从NIB文件加载自定义单元格抛出NSInternalInconsistencyException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)