你好,請做以下類似代碼 -
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 300, 400)];
[self.view addSubview:scrollView];
array=[[NSMutableArray alloc]init];
UIImageView *img1=[[UIImageView alloc]initWithFrame:CGRectMake(20, 0, 100, 100)];
UIImageView *img2=[[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 100, 100)];
UIImageView *img3=[[UIImageView alloc]initWithFrame:CGRectMake(20, 200, 100, 100)];
[img1 setImage:[UIImage imageNamed:@"images.png"]];
[img2 setImage:[UIImage imageNamed:@"images.png"]];
[img3 setImage:[UIImage imageNamed:@"images.png"]];
[array addObject:img1];
[array addObject:img2];
[array addObject:img3];
for(int i=0;i<[array count];i++)
[scrollView addSubview:[array objectAtIndex:i]];
然後刪除所有視圖和空數組繼buttonTouchUpInside()的代碼 -
for(int i=0;i<[array count];i++){
[[array objectAtIndex:i] removeFromSuperview];
[array removeObjectAtIndex:i];
}
請上傳您所使用的代碼,請。 – 2012-01-13 10:14:58
我假設addSubView:UIImageView不完全是這樣的,你使用的是一個UIImageView的實例嗎?你到底在哪裏認爲有泄漏? – 2012-01-13 10:49:25
這段代碼很好,因爲你已經提出了它。該錯誤必須在代碼中的其他地方。你需要發佈更多的周邊代碼,以便我們找到問題。這可能是因爲你是雙釋放項目,或者你意外地將你的數組初始化爲一個不可變數組而不是可變數組。你的代碼中是否有黃色警告? – 2012-01-13 12:38:31