我在UIScrollView上添加了UIImageView,但是当数组计数很高时我的应用程序崩溃了。
这是我的代码
scr=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 60, 320, 320)];
scr.tag=1000;
[scr setDelegate:self];
[self.view addSubview:scr];
dispatch_queue_t queeee =dispatch_queue_create("raj", 0);
int countt=200;
for(int i=0;i<countt;i++)
{
CGRect rectt=CGRectMake((i%3*90)+30,(i/3*90)+40,80,70);
UIImageView *asyImagee = [[UIImageView alloc]initWithFrame:rectt];
dispatch_async(queeee, ^{
NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
__block UIImage *imgg=[UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^
{
asyImagee.image=imgg;
imgg=nil;
});
});
asyImagee.tag=i;
[scr addSubview:asyImagee];
asyImagee=nil;
}
[scr setContentSize:CGSizeMake(0, countt/3*110)];
使用int countt = 100正常工作; 但崩溃了200;