2011-12-07 100 views
14

我已经使用Xcode 4.2创建了一个基于故事板的iOS应用程序。 我的一个屏幕包含一个使用动态自定义单元的UITableViewController。在故事板和UISeachDisplayController中使用XCode 4.2中的动态定制UITableViewCell

到目前为止 - 太好了。

现在,我想添加一个UISearchDisplayController来允许过滤我的列表。

出于某种原因,UISearchDisplayController将不显示我的定制单元,我不能找到一种方法来迫使它...

这是我的cellForRowAtIndexPath方法如下:

- (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;  
} 

关于如何使这项工作的任何想法?我的意思是,我的UISearchDisplayController表会显示正确的结果数量(我知道,因为我可以点击它们,并且我添加了NSLog以让我知道我点击了什么......)

这是我的表视图 This is my table view

这是搜索显示表的样子...... This is how the search display table looks like...

我的问题/问题是如何使UISearchDisplayController表视图显示我的定制单元?

赞赏任何帮助...

鲁文

+0

可以使用的tableView的参考比较经常检查的差异。 –

+0

请注意我的问题是,由于某种原因searchResultsTableView不显示我的客户单元格。这就是我试图解决的问题(看我添加到帖子中的图片) – Reuven

回答

27

回答特定查询

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
} 

对于完整的示例,有sample code from apple's site

Step by step illustration

+2

Spark,你是我的英雄! :-)所以,太令人沮丧了。然而,如此简单而优雅的修复!谢谢! – Reuven

+1

谢谢!我一直在挣扎几个小时。 –

+1

那么问题是什么? – ladookie