2012-02-12 108 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