2

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;
}
4

2 に答える 2

5

使用する

cell = [self.tableView dequeueReusableCellWithIdentifier:sCellID];

それ以外の

cell = [tableView dequeueReusableCellWithIdentifier:sCellID];

次に、絵コンテの原型セルを使用します。

于 2012-05-30T04:11:50.217 に答える
1

UITableViewCell をサブクラス化することで、カスタム セルを作成できます。次に、layoutSubviews でセルの外観を構成する必要があります。

これは、ストーリーボードでセルをデザインしたいという問題を解決しません。UISearchControl の Storyboards への統合はまだ少しぎこちなく、これ以上の解決策はないと思います。

于 2012-02-20T08:04:24.230 に答える