4

通常、選択したセルを次のように取得します。

- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = (CustomCell*) [table cellForRowAtIndexPath:indexPath];
}

しかし、私が使用しているコードでは、テーブル ビューに多くの種類のセルが含まれている可能性があります。選択したセルのクラスを取得するにはどうすればよいですか (たとえばCustomCell、 またはの場合CustomCell2) ?

4

2 に答える 2

21

返されたセルのタイプを確認できます

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[CustomCell class]]) {
     //do specific code
}else if([cell isKindOfClass:[CustomCell2 class]]){
    //Another custom cell
}else{
    //General cell
}
于 2013-06-09T14:40:36.863 に答える