[英]How can I pass an object from fetchedResultsController to a custom cell?
我想将一个对象从fetchedResultsController发送到自定义单元格。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
TWMainViewExpandedCell *cell = (TWMainViewExpandedCell *)[tableView dequeueReusableCellWithIdentifier:StandardExpandedCellIdentifier];
if (cell == nil) {
cell = (TWMainViewExpandedCell *)[[[NSBundle mainBundle] loadNibNamed:@"MainViewStandardCellExpanded" owner:self options:nil] objectAtIndex:0];
}
Work *work = [_fetchedResultsController objectAtIndexPath:indexPath];
cell.workInfo = work; // <- NSLog work.description confirms object exists!
return cell;
// ...
}
从我的自定义单元格的.h和.m文件
。H
@property (strong, nonatomic) Work *workInfo;
.m
- (void) awakeFromNib {
// ...
NSLog(@"%@", _workInfo); // <- why is this nil?
// ...
}
_workInfo,返回零! 我在这里想什么? 如何将对象传递到自定义单元格?
我可以完美地设置文本标签,但不能从FRC发送对象吗?
谢谢!
awakeFromNib
发生在设置workInfo
之前(如果正在重用该单元,则根本不会调用它)。 通常要做的是为workInfo
编写一个自定义属性设置器,例如
- (void)setWorkInfo:(Work *)work
{
if (_work != work) {
_work = work;
//make any Work-related updates to the cell here
}
}
并对设置器中的单元格进行任何与工作相关的更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.