简体   繁体   中英

Using a dynamic custom UITableViewCell in XCode 4.2, with Storyboards and UISeachDisplayController

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM