
Untitled
By: a guest on
May 9th, 2012 | syntax:
None | size: 1.03 KB | hits: 31 | expires: Never
Adding subviews with a loop in UIScrollView generates memory leak
@implementation ProjectsListViewController {
ProjectViewController *icon;
}
int row = 0;
int column = 0;
int page = 0;
for (int i = 0; i < 5; i++) {
icon = [[ProjectViewController alloc] init];
icon.iconPath = @"icon.png";
icon.iconTag = i;
int x = (1024 * page) + ((50 + (10 * column)) + (188 * column));
int y = (40 + (150 * row));
icon.view.frame = CGRectMake(x, y, icon.view.frame.size.width, icon.view.frame.size.height);
[self.scrollView addSubview:icon.view];
// Add a new page if we reach the end of one
if ((column == 4) && (row == 3)) {
row = 0;
column = 0;
page++;
// Add a new line if we reached last column
} else if (column == 4) {
column = 0;
row++;
// Add a column otherwise
} else {
column++;
}
}
icon = [[ProjectViewController alloc] init];
ProjectViewController *projectViewController = [[ProjectViewController alloc] init];