Strange behaviour when selecting a row to open detail view


Hi there,

i am currently working on the Homepwnz0r project. I am stuck at the point where a click on the row of the table view should open the detail view controller (p. 180). When i select a row, the detail view opens on only every second row but when it does, the data of the Possession are displayed correctly. If i click some repeatedly, the app crashes with an exception:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Pushing the same view controller instance more than once is not supported (<ItemDetailViewController: 0x390d110>)’

So i tried logging which [indexPath row] was being sent inside the UITableViewDelegate method: (tableView:didDeselectRowAtIndexPath:)

[code]- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
NSLog(@“did select section: %d, row: %d”,[indexPath section], [indexPath row]);

// check if we need to create an instance of the detailview controller
if (!detailViewController) {
	detailViewController = [[ItemDetailViewController alloc] init];


The strange thing is, the row that i log out never corresponds with the actual row of the position inside the array, there seems to be an offset. Also, the logging only works every second row of the table, the other times the “didSelectRow…:” method just seems not to be called at all.

For debugging i also added the section and the row of the items to the title of each table cell: they are perfectly fine from 0…9.

I also compared my code to the source-code of the book, but everything seems to be basically the same.
Might that be a problem with keeping the itemDetailViewController around and not releasing it after pushing it on the ViewController?
But that would not explain why the delegate method is not beeing called every time i select a row… strange.

Does anybody have an idea where to start looking?


The method you have implemented is tableView:didDeselect

Change that to simply select and you’ll be fine.


Oh my, how could i not see this. :slight_smile:


rhoffmann , just wanted you to know that you were not the only one to get nicked by this one. I can’t stop laughing because I read and re-read and re-read and re-read my code positive that it was correct and matched the book in every way… and in the end I had the same tableView:didDeselect… instead of tableView:didSelect… as you had.

I must need more sleep.

Happy Coding!