Friday, October 21, 2011

iOS 5 & UITableView datasources

It's been a big week for me, primarily because one of our client apps exploded, in no short part to Facebook screwing me over ... but i digress.

Last week also saw me finally upgrade to Lion, enable full disk encryption (Might blog about this later), and start compiling against iOS 5.

As is usual with big changes in the SDK there are always a few bugs, however this one had me confused for a couple of days.

After compiling against iOS 5, i got this message after popping one of the view controllers.
-[YOUR UITableViewDataSource tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x6e78420
Simple, i did something dumb, and over released my datasource class ... But it only happens on iOS 4, not iOS 5. [Cue twilight zone music]. And this code had been stable for well over 6 months before the SDK change [Increase volume].

Generally i a release and nil my objects and set any delegates to nil in my dealloc method. However in this instance i had forgotten to nil out the UITableView's dataSource and delegate properties. The solution was simply:
[_tableView setDataSource:nil];
[_tableView setDelegate:nil];

Now, i'm aware this is 100% my fault, you're always supposed to nil out pointers to non-retained/ weakly referenced objects. As a result i haven't bothered to file a Radar. (Dear apple, you caused me to find a bug in my code ... yeah) However as you can see, for one reason or another i was able to "get away" with it for months, so this post is a fair warning to all to lookout for this.

1 comment:

BANDARAM said...

Thanks for coding