我有一个带有自定义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
Run Code Online (Sandbox Code Playgroud)
这是在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;
}
Run Code Online (Sandbox Code Playgroud)
Wai*_*ain 20
如果你做一点谷歌搜索,你会发现它nsli_superitem与自动布局相关联.这点你走向[[self contentView] addConstraints:imgH];,这点你走向NSString *fmt = @"H:|-0-[listImage]";,以及上[self setListImage:[[UIImage alloc] init]];.
即,您无法基于图像设置布局,因为它不是UI项目.
您可能应该根据某处的图像视图进行布局...
| 归档时间: |
|
| 查看次数: |
4729 次 |
| 最近记录: |