我在 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 崩溃;