你好,请做以下类似代码 -
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