0

我有这个代码,它创建UITableView并让单元格的颜色交替显示白色和灰色。捕获

如何在没有内存泄漏的情况下纠正这个问题?谢谢!

4

1 回答 1

1

你的代码是:

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_white.png"]];

这泄漏了UIImageView. 你分配了它,但之后你没有释放它。

修理:

UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_white.png"]]; 
cell.backgroundView = imageView;
[imageView release];

分析器警告中的箭头有点误导——它们试图通过代码显示执行流程,进入导致泄漏的方法,然后退出。文字信息是重要的部分。

(另外,我怀疑你想要tbl_RowIndex1 % 2,而不是tbl_RowIndex1 %= 2。)

于 2013-01-22T08:16:28.790 回答