簡體   English   中英

在XCode 4.2中使用動態自定義UITableViewCell,使用Storyboards和UISeachDisplayController

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

我已經使用Xcode 4.2來創建基於故事板的iOS應用程序。 我的一個屏幕包含一個UITableViewController,使用動態自定義單元格。

到現在為止還挺好。

現在,我想添加一個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讓我知道我點擊了什么......)

這是我的表格視圖 這是我的表格視圖

這就是搜索顯示表的樣子...... 這就是搜索顯示表的樣子......

我的問題/問題是如何使UISearchDisplayController表視圖顯示我的自定義單元格?

任何幫助贊賞...

魯文

特定於查詢的答案

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

有關完整示例,請獲取Apple網站示例代碼

一步一步的插圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM