Terminate called throwing an exception


#1

Hi there. I am working on getting my UITableViewCell subclass going, and I’m at page 304 of chapter 15. I made my XIB, and I’m pretty sure everything is correct. I’ve copied the code, and I think it’s correct, too.
When I try to run it (iPad simulator), I get this amazingly useless error:

2012-07-11 17:11:36.596 Homepwner[26131:c07] *** Assertion failure in -[HomepwnerItemCell layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2280.1/UIView.m:5695 2012-07-11 17:11:36.599 Homepwner[26131:c07] (null) libc++abi.dylib: terminate called throwing an exception

I got no useful help on Google, and there’s no stack trace. What am I doing wrong?

P. S. I’m using xcode 4.5 DP2 and the 6.0 simulator.


#2

I’ve determined that if I remove all of the subviews (and disconnect all of the connections), it runs fine, with the obvious exception of giving me white boxes for my table cells with no information whatsoever.

If I add any subviews, though, it breaks. This includes subviews that are part of the Homepwner Item Cell but not actually hooked up to anything. For instance, adding a label that just says “Label” and has no connection will throw the exception.


#3

I figured it out. I dragged a UIView in initially instead of a UITableViewCell.


#4

Hi TS,

Sorry to hijack your thread a bit, but got a similar error message -

2012-08-07 09:33:56.977 Homepwner[17264:f803] application:didFinishLaunchingWithOptions: 2012-08-07 09:33:57.194 Homepwner[17264:f803] applicationDidBecomeActive: 2012-08-07 09:33:57.211 Homepwner[17264:f803] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061 2012-08-07 09:33:57.246 Homepwner[17264:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' *** First throw call stack: (0x13d4022 0x1565cd6 0x137ca48 0x9b52cb 0xb8d28 0xb93ce 0xa4cbd 0xb36f1 0x5cd21 0x13d5e42 0x1d8c679 0x1d96579 0x1d1b4f7 0x1d1d3f6 0x1daa160 0x1ce84 0x1d767 0x2c183 0x2cc38 0x20634 0x12beef5 0x13a8195 0x130cff2 0x130b8da 0x130ad84 0x130ac9b 0x1cc65 0x1e626 0x228d 0x21f5 0x1) terminate called throwing an exception(lldb)

Am using Xcode 4.3.2, iPod Touch and/or 5.1 simulator on OSX 10.7.4.

Would appreciate any help. TIA.


#5

Read the error message carefully.


#6

I get the same error. I did read it carefully. According to the athors, the .xib should load if there is no cell to dequeue. It seems not to be doing that.

//===========================// // CUSTOM VIEW USED FOR CELL // //===========================// // Get a new cell or reuse an existing cell HomepwnerItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomepnwerItemCell"]; // Configure the cell cell.nameLabel.text = p.itemName; cell.serialNumberLabel.text = p.serialNumber; cell.valueLabel.text = [NSString stringWithFormat:@"%d", p.valueInDollars]; return cell;

This seems to be where the problem is. I added a log statement to make sure the .xib file is registered on viewDidLoad; that works. But here we have a nil object. I added the following prior to configuring the cell:

if (!cell) { cell = [[HomepwnerItemCell alloc] init]; }

Then it doesn’t crash, but all the cells are BLANK; they do not display anything.

Help please? This is the first time in this excellent book that something is really not working. Thanks.


#7

… OK, it was just a typo:

@“HomepnwnerItemCell”

should be:

@“HomepwnerItemCell”

So … yeah, this “urban” word “Homepnwner” is really not a word, guys. “Homeowner” would have been just fine. I guess you probably did it to help teach newbies about the importance of spelling in code, but to me it’s just annoying to look at code and have my brain say “that is obviously misspelled” every time I look at it. Neither of the above words look like they are spelled correctly. That’s irritating.

Otherwise, great book ; )