0

UITableView を異なる UITableViewCells で埋めようとしています。識別子によって XIB ファイルから 3 つの UITableViewCells のうちの 1 つを選択しようとしましたが、UITableViewCell の識別子の値を取得できません。

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{



MyTableViewCell *cell = (MyTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"CellTwo"];

 if(nil == cell){

  NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
  for (id currentObject in topLevelObjects) {
   if ([currentObject isKindOfClass:[MyTableViewCell class]]) {
    MyTableViewCell *tmpCell = (MyTableViewCell *) currentObject;
    if (tmpCell.identifier == @"CellTwo") {
     cell = (MyTableViewCell *) currentObject;     
    }
    [tmpCell release];
    break;
   }
  } 
 }

 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

 return cell;}
4

1 に答える 1

0

UITableViewCellごとにサブクラスを作成することで、この正確な問題を解決しました。クラスタイプの比較を行うときは、セルのタイプを入れることができます:

        cell = (FooterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"footerTableViewCell"];

        if (cell == nil){

            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CommonTableViewCell" owner:nil options:nil];

            for (id currentObject in topLevelObjects){
                if ([currentObject isKindOfClass:[FooterTableViewCell class]]){
                    cell = (FooterTableViewCell *)currentObject;
                    return cell;
                }
            }
        }

まったく同じ種類のセルの書式設定を再利用するテーブルがいくつかあり、いつでも変更できる共通の XIB にそれらを配置したいと考えていました。そのコントローラーの .h では、3 つのセル タイプのそれぞれに対して UITableViewCell の 3 つのサブクラスを宣言するだけです。

于 2011-07-06T21:57:39.407 に答える