我创建了TableViewController子类,并将其与故事板一起使用。我创建了1个动态原型,并在其子类中使用了其标识符值。它工作并显示在故事板中显示的单元格。但是,当我添加searchDisplayController并将TableViewController作为委托和数据源时,它会显示更正的搜索结果,但TableViewCells的格式不再遵循故事板原型。我在下面使用的代码。我怎样才能让它遵循原型?如何使用故事板动态原型TableViewCell格式化SearchDisplayController结果
- (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;
}
我还计划在自定义单元格。但是想看看是否有更简单的方法。感谢您发布的答案。 – simpleCode 2012-02-20 22:57:20