0

xibでカスタムセルを作成しました。

NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];

セル識別子を付けたいのですが。私は試した

cell.reuseIdentifier=@"";

ただし、その読み取り専用プロパティ。助けてください

4

2 に答える 2

0

Interface Builder でテーブルまたはセルを作成する場合は、オブジェクトの作成時にこのプロパティが設定されるため、Interface Builder で再利用識別子を設定する必要があります。Interface Builderではなく、プログラムでオブジェクト全体を作成する場合にのみ、プログラムで変更(より良い:設定)できます。

于 2013-01-17T11:45:07.390 に答える
0
static NSString *CellIdentifier = @"YourCellName";

YourCellName *cell = (YourCellName *) [tablview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

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

    for (id currentObject in topLevelObjects){
        if ([currentObject isKindOfClass:[UITableViewCell class]]){
            cell =  (YourCellName *) currentObject;
            break;
        }
    }
}
于 2013-01-17T11:45:50.100 に答える