2013-07-24 244 views
0

我想從fetchedResultsController發送一個對象到一個自定義單元格。如何將對象從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發送一個對象?

謝謝!

回答

1

awakeFromNib發生在您設置workInfo之前(如果單元格正在重新使用,則根本不會調用它)。很正常的事情做的,是寫workInfo自定義屬性setter像

- (void)setWorkInfo:(Work *)work 
{ 
    if (_work != work) { 
     _work = work; 
     //make any Work-related updates to the cell here 
    } 
} 

,並進行任何與工作有關的更新二傳手在細胞內。

+0

太棒了,謝謝。 =) – nmdias

相關問題