TableViewController サブクラスを作成し、ストーリーボードで使用しました。動的プロトタイプを 1 つ作成し、その識別子の値をサブクラスで使用しました。ストーリーボードに表示されるように機能し、セルを表示します。しかし、searchDisplayController を追加し、TableViewController をデリゲートとデータソースにすると、正しい検索結果が表示されますが、TableViewCells の形式はストーリーボード プロトタイプに準拠しなくなりました。以下で使用したコード。プロトタイプに追従させるにはどうすればよいですか?
- (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;
}