2012-02-12 72 views
1

我一直在使用儀器測試設備(iOS 5)上的應用程序,並發現了一些內存泄漏。iOS 5 cellForRowAtIndexPath內存泄漏

這是我被從儀器重定向到代碼的一部分(見確切線箭頭):

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     CeldaUltimasFotosViewCell *cell = 
      (CeldaUltimasFotosViewCell *) [self.tableView 
       dequeueReusableCellWithIdentifier:@"CeldaUltimasFotosViewCell"]; 

     if (cell == nil) { 
- - - - > NSArray *topLevelObjects = 
         [[NSBundle mainBundle] 
          loadNibNamed:@"CeldaUltimasFotosViewCell" 
            owner:nil options:nil]; 
      cell = [topLevelObjects objectAtIndex:0]; 
     } 

     // Configure the cell... 
     [[cell titulo] setFont:fuente_titulo]; 
     ... 
     return cell; 
} 

正如你所看到的,我有從加載自定義單元格NIB文件。該單元有三個文件(,customCell.h,customCell.xib)。問題是,我不知道是否必須在單元控制器(現在是空的,沒有方法)中釋放某些東西,因爲這是帶有ARC的iOS 5。

回答

0

查看Table View Programming以及如何從NIB(XIB)文件加載單元格。

https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

怪異的第一件事情是,你是存儲在一個局部變量的單元格。你應該接線自定義單元格到一個屬性的類和所有你在你的代碼中調用是:

[[NSBundle mainBundle] loadNibNamed:@"CeldaUltimasFotosViewCell" owner:self options:nil]; 

按照代碼加載自定義表視圖細胞筆尖文件,你不能出錯。

+0

嗨twilson,感謝您的諮詢。不幸的是,我一直在閱讀這些文件一段時間,但沒有成功。我在那裏看到這個答案在這裏在Stackoverflow去那裏:[鏈接](http://stackoverflow.com/questions/540345/how-do-you-load-custom-uitableviewcells-from-xib-files)。無論如何,如果我錯過了一些東西,我會重新審視它。如果你在我的代碼中看到奇怪的東西,請告訴我。 我會發布,如果我找到解決方案。 再次感謝! – 2012-02-12 12:12:27

+0

我已經添加了一些更詳細的答案。 – twilson 2012-02-12 12:35:25