我有自定义类的单元格原型,我有出口。
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];
的{{1}}设置断点时,它只显示所有出口都是零。
我做错了吗?
答案 0 :(得分:4)
使用在故事板中设置的表格视图单元格时,不应该注册该类,因为这样会使表格视图无法获取您在IB中设置的单元格。我认为你只想在代码中完全设置单元格时注册一个类。
如果你在xib文件中创建单元格,并且有一个自定义类,那么你注册nib而不是类。