2012-01-06 41 views
1

我正在查看來自WWDC#2010的TableViewUpdates示例代碼中的TVAnimationGestures。在他們看來控制器的子類,他們有一個這樣的插座:對於UITableViewCell的子類,是否保留或分配爲該UITableViewCell的屬性

@property (nonatomic, assign) IBOutlet QuoteCell *quoteCell; 

,然後在他們的cellForRowAtIndexPath創建它:

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { 

    static NSString *QuoteCellIdentifier = @"QuoteCellIdentifier"; 

    QuoteCell *cell = (QuoteCell*)[tableView dequeueReusableCellWithIdentifier:QuoteCellIdentifier]; 

    if (!cell) { 

     UINib *quoteCellNib = [UINib nibWithNibName:@"QuoteCell" bundle:nil]; 
     [quoteCellNib instantiateWithOwner:self options:nil]; 
     cell = self.quoteCell; 
     self.quoteCell = nil; 

     if ([MFMailComposeViewController canSendMail]) { 
      UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
      [cell addGestureRecognizer:longPressRecognizer];   
      [longPressRecognizer release]; 
     } 
     else { 
      NSLog(@"Mail not available"); 
     } 
    } 

    Play *play = (Play *)[[self.sectionInfoArray objectAtIndex:indexPath.section] play]; 
    cell.quotation = [play.quotations objectAtIndex:indexPath.row]; 

    return cell; 
} 

我的問題是,爲什麼他們所使用的屬性分配,而不是挽留?謝謝。

回答

0

該插座僅用於訪問從筆尖加載的單元格(在加載筆尖時,所有者自己),這意味着在筆尖單元格中,所有者將被設置爲視圖控制器的類,並且整個單元的出口將鏈接到quoteCell)。

這比替代方法更加方便,它將nib加載到數組中並挑選出第一個對象。

出口值立即設置爲零,因此如果它被分配或保留,它沒有真正的區別。

相關問題