私はTableViewControllerサブクラスを作成し、ストーリーボードで使用しました。私は1つのDynamic Prototypeを作成し、そのサブクラスで識別子値を使用しました。ストーリーボードに表示されているようにセルを表示します。しかし、searchDisplayControllerを追加して、TableViewControllerをデリゲートとデータソースにすると、corrct検索結果が表示されますが、TableViewCellのフォーマットはストーリーボードのプロトタイプに従わなくなりました。コード私は以下で使用しました。プロトタイプに従うにはどうすればいいですか?ストーリーボードDynamic Prototypes 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