0

UITableview にカスタム セルが必要です。私は以下でそれを試しました:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

    NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:nil options:nil];

    for (UIView *view in views) {
        if([view isKindOfClass:[UITableViewCell class]])
        {
            cell = (CustomCell*)view;
        }
    }
}
[cell setLabelText:[daten objectAtIndex:indexPath.row]];
return cell;

}

しかし、その行で例外が発生しています:

CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
4

4 に答える 4

0

ビルドフォルダをクリーンアップするか、[シミュレータ]->[コンテンツと設定のリセット]を試してください。

于 2012-09-24T11:14:35.560 に答える
0

最新の ios SDK を使用していない場合は、@synthesize commentLabel を書いていることを確認してください。カスタムセルで

于 2012-09-24T11:01:18.820 に答える
0

これは、カスタムセルを作成してクラスから呼び出す方法です:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:[cell reuseIdentifier]];

    if (cell == nil)
    {
        [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = customCell;
        customCell = nil;
    }

    // Configure the cell.
    cell.serialLabel.text = [[NSNumber numberWithInt:indexPath.row+1]stringValue];
    cell.textLabel.textColor=[UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    }
于 2012-09-24T10:23:04.767 に答える
0

XIBファイルで接続が失われたことはほぼ確実です。commentLabel がまだ存在する場合は、それを削除して新しいアウトレットを作成するか、アウトレット セクションを確認して余分な接続を削除する必要があります。

編集: このエラーは、IB の同じラベルに 2 つのアウトレットが接続されている場合に発生します。

ここに画像の説明を入力

于 2012-09-24T10:58:32.683 に答える