1

我正在制作一个简单的照片库,在滚动视图中放置大约 60 张 1024x768 的图像会导致我的执行速度非常慢甚至应用程序崩溃,我做错了什么?

-(void)sethomeview:(UIScrollView *)selscroll numimg:(int)numimg section:(NSString *)section
{   selscroll.delegate = self;
    selscroll.contentSize = CGSizeMake(160*numimg,80);
    sezione=section;

  for (int i=1; i<numimg+1; i++)
  {
      NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:[NSString stringWithFormat:@"/%@%d.jpg",sezione,i]];        
      UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake((i-1)*165,0, 160, 80)];
      [button setImage:[UIImage imageWithContentsOfFile:fullpath] forState:UIControlStateNormal ];
      [button setTitle:sezione forState:UIControlStateNormal];
      [button addTarget:self action:@selector(homepremuta:) forControlEvents:UIControlEventTouchDown];
      button.tag =i;
      [selscroll addSubview:button];

  }
}
4

0 回答 0