【发布时间】:2011-08-09 06:54:46
【问题描述】:
我正在尝试在 UIButton 上上传 8-10 个缩略图。图像通过链接直接加载到我的服务器,例如。 www.abc.com/fire.png。我已将这些 UIButtons 放置在 Scrollview 中。以下代码是我如何实现它。但是每当调用此方法时,我的应用程序都会挂起,因为我猜图像需要时间才能加载到按钮上。我怎样才能阻止我的应用卡住几秒钟??
- (void)loadSCRView
{
[self.view addSubview:scrollView];
for (i = 0; i < [myEngine.logoUrlArr count]; i++)
{
NSString *imageName = [NSString stringWithFormat:@"%@",[myEngine.logoUrlArr objectAtIndex:i]];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:imageName] options:NSDataReadingUncached error:nil]];
UIButton *btn = [[UIButton alloc]init];
[btn setImage:image forState:UIControlStateNormal];
[btn setFrame:CGRectMake(x, 4, 57, 57)];
x=x+ 70.00;
btn.tag = i;
[scrollView addSubview:btn];
[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchDown];
UILabel *label = [[UILabel alloc]init];
label.text = [myEngine.nameArr objectAtIndex:i];
[label setFont:[UIFont fontWithName:@"Helvetica" size:12]];
[label setTextColor:[UIColor whiteColor]];
[label setBackgroundColor:[UIColor clearColor]];
[label setFrame:CGRectMake(btn.frame.origin.x , 59, 70, 20)];
//[label setFrame:CGRectMake(100 , 59, 70, 20)];
y=y+ 100.00;
[scrollView addSubview:label];
[btn release];
[label release];
}
【问题讨论】:
-
我面临着同样的问题,那么哪一个是解决这些问题的最佳解决方案.. 延迟加载或 NSOperationQueue?任何人都可以给我一些指导。