Careful with auto-completion!


#1

So I’ve been working thru the book, and I’m up to chapter 28, working on the Nerdfeed app. Everything was working almost as expected, except for one small detail. When I clicked on an entry to view the post the first time, nothing happened. When I clicked on a second entry, it showed me the post for the first entry. Each click showed me the post for the previous click instead of the current one.

At first I suspected an off-by-one error, but I checked thru the code and didn’t see where that could be happening, and further testing by clicking random entries showed that I really was seeing the post for the previously-clicked entry and not for (row - 1). So I downloaded the completed code for chapter 28 and compared it to mine, and it appeared identical.

After a couple of days away from it, I started looking at the project again. The problem had to be in ListViewController.m, since that’s where the click/tap is handled. This time, after only a couple of minutes, it hit me. Instead of tableView:didSelectRowAtIndexPath:, I had tableView:DidDeselectRowAtIndexPath:. The code was doing exactly what I told it to do – showing me the post for the cell that I had just left.

Lesson learned: Be careful with auto-completion! :slight_smile:


#2

That should be a no brainer but it is amazing how often it bites me in the butt even after years of programming. Thanks for the reminder.


#3

Every time I teach our iOS bootcamp someone in class makes this exact same auto-complete error. Easy mistake to make!