hachinoBlog

hachinobuのエンジニアライフ

カスタムUITableViewCellの再利用

自分で定義したカスタムセルのxibファイルを読み込む場合、xibファイルのIdentifierに
実際のコードで使用するCellIdentifierと同じ名前の値を入れてあげないと再利用されない。

例:

static NSString *CellIdentifier = @"CustomCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = aTableViewCell;
        aTableViewCell = nil;
    }

この場合はxibファイルのIdentifierにCustomCellと記載すること。