{"id":5135,"date":"2014-03-30T19:09:11","date_gmt":"2014-03-30T19:09:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/uitableview-load-a-custom-cell-from-nib-file-throws-nsinternalinconsistencyexception-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:09:11","modified_gmt":"2014-03-30T19:09:11","slug":"uitableview-load-a-custom-cell-from-nib-file-throws-nsinternalinconsistencyexception-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/uitableview-load-a-custom-cell-from-nib-file-throws-nsinternalinconsistencyexception-collection-of-common-programming-errors\/","title":{"rendered":"UITableView load a Custom Cell from NIB file throws NSInternalInconsistencyException-Collection of common programming errors"},"content":{"rendered":"<p>In an ios application I have a UITableView. In the <code>cellForRowAtIndexPath<\/code> method I need to return a custom cell using it&#8217;s NIB name. For that I use <code>loadNibNamed<\/code>. (I will fill the data in the cell after the load in the &#8216;willDisplayCellforRowAtIndexPath&#8217;)<\/p>\n<p>MyItemCell is a XIB file (MyItemCell.xib) that containg 2 UIImageView and a UIButton (Each item has a tag)<\/p>\n<p>This is my code:<\/p>\n<p>In my viewController<\/p>\n<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath\n{\n    return [ViewHelper loadCustomCellWithNibName:@\"MyItemCell\" owner:self];\n}\n<\/code><\/pre>\n<p>And the method to load the Custom cell from NIB<\/p>\n<pre><code>+ (UITableViewCell *) loadCustomCellFromNib:(NSString *)nibName owner:(id)owner\n{\n    UITableViewCell *cell = nil;\n    NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:owner options:nil];\n    if([nibObjects count] &gt; 0 )\n    {\n        cell = [nibObjects objectAtIndex:0];\n    }\n    else\n    {\n        NSLog(@\"Failed to load %@ XIB file!\", nibName);\n    }\n    return cell;\n}\n<\/code><\/pre>\n<p>Everything works correctly in all the testings. However I received a crash from some users that I was unable to reproduce.<\/p>\n<p>This is the crash:<\/p>\n<pre><code>NSInternalInconsistencyException\n\nCould not load NIB in bundle: 'NSBundle  (loaded)' with name 'MyItemCell'\n<\/code><\/pre>\n<p>The stack trace:<\/p>\n<pre><code>0 CoreFoundation                        0x39b432a3 __exceptionPreprocess + 163 + 162\n\n1 libobjc.A.dylib                       0x33a3297f objc_exception_throw + 31 + 30\n\n2 CoreFoundation                        0x39b431c5 -[NSException initWithCoder:] + 1\n\n3 UIKit                                 0x32e12491 -[UINib instantiateWithOwner:options:] + 1637 + 1636\n\n4 UIKit                                 0x32e1a1d7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 139 + 138\n\n5 MyApp                                 0x00047ded +[ViewHelper loadCustomCellFromNib:owner:] (ViewHelper.m:349)\n\n6 MyApp                                 0x00034003 -[BuildViewController tableView:cellForRowAtIndexPath:] (BuildViewController.m:2432)\n\n7 UIKit                                 0x32cc0545 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 413 + 412\n\n8 UIKit                                 0x32ca530b -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1311 + 1310\n\n9 UIKit                                 0x32cbc7c7 -[UITableView layoutSubviews] + 207 + 206\n\n10 UIKit                                0x32c78803 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 259 + 258 \n<\/code><\/pre>\n<p>The problem is that I was not able to reproduce this crash.<\/p>\n<p>Any idea on what might have caused the crash? Or any solutions to avoid such an error?<\/p>\n<p>Thanks a lot for any help<\/p>\n<p><strong>EDIT:<\/strong><\/p>\n<p>Just to clarify more, This is working perfectly fine on any testing that I&#8217;m doing. This crash appeared only 1 time for 1 user so the problem is not with the code. I am just searching for reasons that might cause this crash in a very specific scenario. Thanks<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In an ios application I have a UITableView. In the cellForRowAtIndexPath method I need to return a custom cell using it&#8217;s NIB name. For that I use loadNibNamed. (I will fill the data in the cell after the load in the &#8216;willDisplayCellforRowAtIndexPath&#8217;) MyItemCell is a XIB file (MyItemCell.xib) that containg 2 UIImageView and a UIButton [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5135","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5135"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5135\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}