2012-01-06 67 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加载到数组中并挑选出第一个对象。

出口值立即设置为零,因此如果它被分配或保留,它没有真正的区别。

相关问题