1

アウトレットがあるカスタムクラスのセルプロトタイプがあります。

アウトレット接続 セル プロトタイプの IB に設定されたカスタム クラス

STRMEpisodeCell.h

#import <UIKit/UIKit.h>
#import "Show.h"

@interface STRMEpisodeCell : UITableViewCell
@property (weak, nonatomic) Show *show;
@property (weak, nonatomic) IBOutlet UILabel *showLabel;
@property (weak, nonatomic) IBOutlet UILabel *episodeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *posterView;
@end

STRMEpisodeCell.m

#import "STRMEpisodeCell.h"

@interface STRMEpisodeCell ()

@end

@implementation STRMEpisodeCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

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

    // Configure the view for the selected state
}

- (void)setShow:(TVDbShow *)show
{
    _show = show;
    self.showLabel.text = show.title;
}

@end

STRMViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.episodeTable.dataSource = self;
    [self.episodeTable registerClass:[STRMEpisodeCell class] forCellReuseIdentifier:@"episode"];

    self.list = //loading data here;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    STRMEpisodeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"episode"];
    cell.show = self.list[indexPath.row];
    return cell;
}

ブレークポイントをオンに設定するcell.show = self.list[indexPath.item];cell、すべてのアウトレットが nil であることが示されます。

私は何か間違ったことをしていますか?

4

1 に答える 1

4

ストーリーボードで設定したテーブル ビュー セルを使用する場合、クラスを登録しないでください。IB で設定したセルをテーブル ビューが取得できなくなるためです。セル全体をコードで設定する場合にのみ、クラスを登録したいと思います。

xib ファイルでセルを作成し、カスタム クラスがある場合は、クラスではなく nib を登録します。

于 2013-03-22T01:06:53.723 に答える