I’m using ios5 storyboard and have a tablview with a uisearchbar that I’m using the filter the results. I’m following the tip from the following blog post where I also posed this question
http://code-ninja.org/blog/2012/01/08/ios-quick-tip-filtering-a-uitableview-with-a-search-bar/:
The problem I see is that when getting back items from my filtered array the custom UITableViewCell comes back as null. In iOS5 I understand you should only have to get a cell via dequieReusableCell and not explicitily init a cell. However when the search in the search bar successfully matches the cell comes back as null. I’m not sure how I can manually init my cell with the custom style. Any ideas?
Here’s a snippet from my cellForRowAtIndexPath method.
ItemCell *cell = (ItemCell *)[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
self.searchBar.tableView.
if (cell == nil){
NSLog(@”Why is this happening when I get a successfull match from the search bar?”);
}
This causes the following error :
Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath
* Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:’
You’re calling
dequeueReusableCellWithIdentifier:on the wrong table.Your prototypes are defined in your primary table, and need to be dequeued from there. When performing a search, you’re being asked to fill out a special search table. That table doesn’t contain your cell prototypes, and it doesn’t search the original table for the prototypes!
Your table is still available as
self.tableView. And you can dequeue from there, even for the search results table.Instead of this:
Use this: