繁体   English   中英

如何将对象从fetchedResultsController传递到自定义单元格?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM