我正在用顯示圖像的自定義單元格構建UItableView。問題是,當我向下滾動時,以前的單元格似乎沒有執行dealloc並且設備內存正在填滿。UITableView單元格沒有執行dealloc
這是我的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
CustomTableCellView *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CustomTableCellView alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
Article *tempArticle = [_objects objectAtIndex:indexPath.row];
cell.titel.text = tempArticle.title;
cell.subTitle.text = tempArticle.subTitle;
cell.category.text = tempArticle.category;
if(tempArticle.imageUrl){
[cell.image setImageWithURL:[NSURL URLWithString:tempArticle.imageUrl]];
} else {
cell.image.image = [UIImage imageNamed:@"video"];
}
return cell;
}
單元格未被表視圖釋放,因爲它們被重用。如果你在你的'if'中放置一個斷點,你會注意到在初始加載後,它不會再停留在那裏,因爲表可以使現有的單元出隊。問題可能在其他地方。 –
你猜測單元沒有被釋放。通過儀器運行您的應用程序,並獲取幾個內存快照,以確切查看哪些對象正在使用內存。 – Abizern
好吧,我知道它被重用了,但它爲什麼會填滿內存? – Verendus