Pregunta

I have this code which created with UITableView and making the cell's color show alternatively white and grey. Capture

How can I correct this, without memory leak? Thanks!

¿Fue útil?

Solución

Your code is:

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

This leaks the UIImageView. You allocated it, but you didn't release it afterwards.

To fix:

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

The arrows in the analyzer warning are a little misleading -- they're trying to show the flow of the execution through the code, into the method that caused the leak, and then out. The textual messages are the important part.

(Also, I suspect you want tbl_RowIndex1 % 2, not tbl_RowIndex1 %= 2.)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top