如何使用Storyboard Dynamic Prototypes TableViewCell格式化SearchDisplayController结果

sim*_*ode 2 objective-c storyboard searchdisplaycontroller ios

我创建了TableViewController子类并将其与故事板一起使用.我创建了1个动态原型并在子类中使用了它的Identifier值.它工作并显示故事板中显示的单元格.但是当我添加searchDisplayController并使TableViewController成为委托和数据源时,它会显示corrct搜索结果,但TableViewCells的格式不再遵循storyboard原型.我在下面使用的代码.我怎样才能让它跟随原型?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Contact Cell";
    static NSString *sCellID = @"Contact Cell";
    UITableViewCell *cell;
        if (tableView == self.searchDisplayController.searchResultsTableView) {
            cell = [tableView dequeueReusableCellWithIdentifier:sCellID];
            if (cell == nil) 
            {            
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:sCellID];
            }
        }
        else
        {
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) 
            {            
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
        }


    // ask NSFetchedResultsController for the NSMO at the row in question
    Contact *contact = [self.fetchedResultsController objectAtIndexPath:indexPath];
    // Then configure the cell using it ...
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.imageView.image = [UIImage imageNamed:@"1234_profile.png"];
    cell.textLabel.text = [contact.lastName stringByAppendingFormat:@", %@",contact.firstName];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", contact.occupation, contact.companyName];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

nav*_*el7 5

使用

cell = [self.tableView dequeueReusableCellWithIdentifier:sCellID];
Run Code Online (Sandbox Code Playgroud)

代替

cell = [tableView dequeueReusableCellWithIdentifier:sCellID];
Run Code Online (Sandbox Code Playgroud)

然后使用故事板的原型单元.