[英]iOS 5 cellForRowAtIndexPath Memory Leak
使用Instruments時,我已經在設備(iOS 5)上測試了該應用程序,發現了幾次內存泄漏。
這是我從Instruments重定向到的代碼的一部分(請參見箭頭以獲取確切的行):
- (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.m
, customCell.h
, customCell.xib
)。 事實是,我不知道是否必須在單元控制器中釋放某些內容(現在為空,沒有方法),因為這是帶有ARC的iOS 5。
看一下“表視圖編程”以及如何從NIB(XIB)文件加載單元。
奇怪的第一件事是您將單元格存儲在局部變量中。 您應該將自定義單元格連接到類中的一個屬性,並且您在代碼中調用的全部是:
[[NSBundle mainBundle] loadNibNamed:@"CeldaUltimasFotosViewCell" owner:self options:nil];
遵循從Nib文件加載自定義表格視圖單元格中的代碼,您不會出錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.