4

5 つの静的セルを含むテーブルビューがあります。テーブルビューには常に 5 つしかないため、これらは静的です。

カスタムセル

UIImageViews を各セルの中央に配置する必要があるため、カスタムセルが必要です。これは、ボタンの画像だけが含まれるためです。UIImageView アウトレットを持つ MyCustomCell クラスを作成し、それをアウトレットに接続しました。

セル シブ

次に、テーブルビューコントローラークラスでこれを行いました:

#pragma mark - TableView Cell Methods
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyCustomCell *cell = [[MyCustomCell alloc] init];

    switch (indexPath.row) {
        case 0:
            // Use Custom Cell
            cell.thumbnailImageView.image = [UIImage imageNamed:@"button.png"];
            break;
        case 1:
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
            // USE IMAGE INSTEAD
            cell.thumbnailImageView.image = [UIImage imageNamed:@"button1.png"];
            break;
        case 2:
            cell.thumbnailImageView.image = [UIImage imageNamed:@"button2.png"];
            break;
        case 3:
            cell.thumbnailImageView.image = [UIImage imageNamed:@"button3.png"];
            break;
        case 4:
            cell.thumbnailImageView.image = [UIImage imageNamed:@"Search.png"];
            break;
        default:
            break;
    }
    return cell;
}

MyCustomCell.m:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

セルは空白で表示されます。MyCustomCell の代わりに UITableViewCell を使用していた場合、問題なく動作しました。そのため、なぜ今失敗したのかわかりません。

4

2 に答える 2