Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.03 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Adding subviews with a loop in UIScrollView generates memory leak
  2. @implementation ProjectsListViewController {
  3.     ProjectViewController *icon;
  4. }
  5.        
  6. int row = 0;
  7. int column = 0;
  8. int page = 0;
  9.  
  10. for (int i = 0; i < 5; i++) {
  11.  
  12.     icon = [[ProjectViewController alloc] init];
  13.  
  14.     icon.iconPath = @"icon.png";
  15.     icon.iconTag = i;
  16.  
  17.     int x = (1024 * page) + ((50 + (10 * column)) +  (188 * column));
  18.     int y = (40 + (150 * row));
  19.  
  20.     icon.view.frame = CGRectMake(x, y, icon.view.frame.size.width, icon.view.frame.size.height);
  21.  
  22.     [self.scrollView addSubview:icon.view];
  23.  
  24.     // Add a new page if we reach the end of one
  25.     if ((column == 4) && (row == 3)) {
  26.         row = 0;
  27.         column = 0;
  28.         page++;
  29.  
  30.         // Add a new line if we reached last column
  31.     } else if (column == 4) {
  32.         column = 0;
  33.         row++;
  34.  
  35.         // Add a column otherwise
  36.     } else {
  37.         column++;
  38.     }
  39. }
  40.        
  41. icon = [[ProjectViewController alloc] init];
  42.        
  43. ProjectViewController *projectViewController = [[ProjectViewController alloc] init];