我有一个带有自定义 TableViewCell 的 tableView。我没有使用 .xib 文件来进行布局。问题是当表应该加载时,我收到以下错误:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage nsli_superitem]: unrecognized selector sent to instance 0x91899b0'
我不确定我在这里做错了什么。这是单元格的 .m 文件。
#import "TCMExhibitListCell.h"
@implementation TCMExhibitListCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setListImage:[[UIImage alloc] init]];
[self setTitleLabel:[[UILabel alloc] init]];
NSDictionary *names = @{@"listImage" : [self listImage]};
NSString *fmt = @"H:|-0-[listImage]";
NSArray *imgH = [NSLayoutConstraint constraintsWithVisualFormat:fmt
options:0
metrics:nil
views:names];
[[self contentView] addConstraints:imgH];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
这是单元格在 tableview 控制器中加载的位置
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TCMExhibitListCell *c = [tableView dequeueReusableCellWithIdentifier:@"TCMExhibitListCell"];
if (!c) {
c = [[TCMExhibitListCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"TCMExhibitListCell"];
}
TCMExhibitRemote *e = [[self exhibits] objectAtIndex:[indexPath row]];
NSString *imageFile = [NSString stringWithFormat:@"%@/%@.jpg",[[TCMExhibitFeedStore sharedStore] imagePathByType:@"listImage"],[e image]];
[c setListImage:[UIImage imageNamed:imageFile]];
return c;
}