我想将一个对象从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;
// ...
}
来自我的Custom Cell的.h和.m文件
·H
@property (strong, nonatomic) Work *workInfo;
的.m
- (void) awakeFromNib {
// ...
NSLog(@"%@", _workInfo); // <- why is this nil?
// ...
}
_workInfo,正在返回零!我在这里错过了什么?如何将对象传递给自定义单元格?
我可以完美地设置文本标签,但不能从我的FRC发送对象吗?
谢谢!
答案 0 :(得分:1)
awakeFromNib
在您设置workInfo
之前发生(如果重用该单元格,则根本不会调用它)。这里正常的做法是为workInfo
编写一个自定义属性设置器,如
- (void)setWorkInfo:(Work *)work
{
if (_work != work) {
_work = work;
//make any Work-related updates to the cell here
}
}
并对setter中的单元格进行任何与Work相关的更新。