簡體   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