2012-02-19 5 views
2

私は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; 
} 

答えて

1

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

これは、ストーリーボードでセルをデザインしたいという問題を解決しません。私は、ストーリーボードにUISearchControlを統合することは、やや不器用であり、より良い解決策はないと考えています。

+0

私もカスタムセルを計画していました。しかし、より簡単な方法があるかどうかを見たいと思っていました。投稿された回答をありがとう。 – simpleCode

5

使用

cell = [self.tableView dequeueReusableCellWithIdentifier:sCellID]; 

代わりに

cell = [tableView dequeueReusableCellWithIdentifier:sCellID]; 

そしてストーリーボードのプロトタイプセルが使用されます。

関連する問題