I've used Xcode 4.2 to create a storyboard-based iOS application. One of my screens contains a UITableViewController, using dynamic custom cells.
So far - so good.
Now, I wanted to add a UISearchDisplayController to allow filtering my list.
For some reason, the UISearchDisplayController won't display my custom cells, and I can't find a way to force it...
This is what my cellForRowAtIndexPath method looks:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"QueueListCell";
QueueListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[QueueListTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
assert(cell);
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {
indexPath = [_indexPathsForSearchResults objectAtIndex:indexPath.row];
}
// Set up the cell...
NSDictionary* itemDict = [_ListItems objectAtIndex:indexPath.row];
cell.labelQueueName.text = [itemDict objectForKey:kQueueName];
cell.labelQueueNumItems.text = [[itemDict objectForKey:kQueueNumItems] stringValue];
return cell;
}
Any thoughts on how to get this working? I mean, my UISearchDisplayController table DOES show the correct number of results (I know that since I can click on them, and I added an NSLog to let me know what I'm clicking on...)
This is my table view
This is how the search display table looks like...
My problem/question is how to make the UISearchDisplayController table view show my custom cells?
Any help appreciated...
Reuven
Answer specific to query
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
For Complete example, have the sample code from apple's site.
Step by step illustration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With