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