在我的UITableView的viewDidLoad中,我正在调用:
[self registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellReuseIdentifier:@"MyCellRI"];
然后在cellForRowAtIndexPath中我有以下内容:
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCellRI"];
[cell setup:[items objectAtIndex:indexPath.row]];
在设置方法中,我看一下[self subviews]来浏览子视图并根据键/值分配内容但是在这个循环中我找到了UITableViewCellContentView,但我没有看到我在NIB中定义的自定义视图。
在NIB中我已经分配了文件所有者&我单元格的自定义类。单元格显示我在子视图中找不到NIB视图。
请告知。
詹姆斯
答案 0 :(得分:0)
通过子视图迭代是一项艰苦的工作)尽量避免使用它。这不是很好的做法,因为它不可靠。例如,如果您决定更改自定义单元格UI,则必须更改迭代子视图的方法。
尝试执行以下操作:
假设有UIImage的自定义单元格和3个字符串(例如人名,年龄和手机号码)
在自定义单元格中实现3个函数,以按如下方式设置此值:
MyCustomCell.h ...... .h文件标准代码然后在最后......
@propert(nonatomic, strong) IBOutlet UIImageView *myImage;
@propert(nonatomic, strong) IBOutlet UILabel *myFirstLabel;
@propert(nonatomic, strong) IBOutlet UILabel *mySecondLabel;
@propert(nonatomic, strong) IBOutlet UILabel *myThirdLabel;
- (void)setUIimage:(UIImage *)_image;
- (void)setFirstString:(NSString *)_string;
- (void)setSecondString:(NSString *)_string;
- (void)setThirdString:(NSString *)_string;
MyCustomCell.m:
@synthesize myImageView, myFirstLabel, mySecondLabel, myThirdLabel;
- (void)setUIimage:(UIImage *)_image {
self.myImageView.image = _image;
}
- (void)setFirstString:(NSString *)_string {
self.myFirstLabel.text = _string;
}
- (void)setSecondString:(NSString *)_string {
self.mySecondLabel.text = _string;
}
- (void)setThirdString:(NSString *)_string {
self.myThirdLabel.text = _string;
}
最后在你的tableView控制器cellForRowAtIndexPath
中[myCustomCell setUiImage:someImage];
[myCustomCell setFirstString:oneString];
[myCustomCell setSecondString:twoString];
[myCustomCell setThirdString:threeString];
希望这种方法对您有所帮助。随意询问您是否有一些问题