0
我是Objective C和IOS编程的新手,请耐心等待。将UIButtons添加到UIScrollView以编程方式直到循环完成才显示
我正在从我的服务器,我使用的图像或按钮添加到我的观点我认为是一个UIScrollView,
下面的代码的伟大工程,做一个JSON字符串,正是我想要的,但我只看到所有按钮一旦循环完成需要一些时间。
我期待的是看到每个按钮都被逐一添加到视图中。有没有更好的方法来实现这一点,或者这是我所描述的预期行为。
谢谢
for (NSDictionary *num in jsonOBJ) {
fullURL = [urlWithOut stringByAppendingString:[num objectForKey:@"src"]];
img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:fullURL]]];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(3+i*h, 3+i*w,76, 76);
button.layer.borderWidth = 1.0;
button.layer.borderColor = [UIColor redColor].CGColor;
[button addTarget:self action:@selector(push:) forControlEvents:UIControlEventTouchUpInside];
[self.scroll addSubview:button];
[button setImage:img forState:UIControlStateNormal];
[img release];
NSString *string = @"";
NSString *realstring = [string stringByAppendingString: [num objectForKey:@"id"]];
button.tag = [realstring intValue];
self.scroll.contentSize = CGSizeMake(320,total);
}
你能指导我在正确的方向为图像加载 – ryuutatsuo 2012-02-04 09:00:52
我做了一个简单的项目,我的学生前一段时间解释如何加载图像在后台线程 - https://github.com/dunenkoff/WebImages,看看里面KDImageView类。 – 2012-02-04 09:05:24