Just playing around with some sample code and hit on an unexpected problem with UITableViewDataSource.
My test app is the basic "Navigation Bar" iPhone template, to display a list. I've added an NSObject subclass to implement UITableViewDataSource, embedded this class into the RootViewController.xib and connected it to the TableView's dataSource outlet.
The app starts up OK. DataSource gets initialised and table view is populated with first 10 rows. Log:
2011-05-11 10:20:03.367 JustAList[10562:207] JALMainViewDataSource init
2011-05-11 10:20:03.375 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.378 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.380 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.381 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.383 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.384 JustAList[10562:207] cellForRowAtIndexPath <JALMainV开发者_运维技巧iewDataSource: 0x5d23730>
2011-05-11 10:20:03.384 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.385 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.385 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
2011-05-11 10:20:03.386 JustAList[10562:207] cellForRowAtIndexPath <JALMainViewDataSource: 0x5d23730>
Soon as I scroll however (ie. new cell is required) the app crashes:
2011-05-11 10:20:06.249 JustAList[10562:207] -[__NSCFTimer tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x5d23730
2011-05-11 10:20:06.379 JustAList[10562:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x5d23730'
It's just called cellForRowAtIndexPath 10 times in a row without problem, now it says unrecognized selector?
Has it maybe got sth to do with the way that I'm initialising (ie. implicitly from nib)? Perhaps it's being prematurely released? Hmm.. have ideas to check out, but wanted to post question here first before wasting too much time (I actually intended to try out sth completely different, wasn't anticipating this problem!).
Hope someone can help? Cheers!
I solved this for myself almost immediately (see my own comment).
Thanks for the reminder 'idz'. I was unable to set it as answered immediately - if I remember correctly S.O. said I had to wait 24hrs before setting a question as answered.
精彩评论