I want to do lazy loading using an UIScrollview and want to add some photos which come as a response from a web service.
The code I have written so far is as follows:
for (int j=0;j<9;j++) {
for (int i=0; i<[mainRestaurantArray count];i++) { //**mainRestaurantArray is the array which has the uiimage in one of it index**
if ([[[mainRestaurantArray objectAtIndex:i] valueForKey:@"Image"] isKindOfClass:[UIImage class]]) {
[CombineArray addObject:[mainRestaurantArray objectAtIndex:i]];
//NSLog(@"cnt=>%d array==>%@",cnt,[CombineArray objectAtIndex:cnt]);
UIButton* btn = [[UIButton alloc]init];
btn.tag = cnt;
btn.frame = CGRectMake(15+(cnt%5)*60, 15+(cnt/5)*60,Width,Height);
btn.backgroundColor = [UIColor greenColor];
[btn setBackgroundImage:[[CombineArray objectAtIndex:cnt] valueForKey:@"Image"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(Buttonclick:) forControlEvents:UIControlEventTouchUpInside];
[ScrlPhotos addSubview:btn]; //Add the UIButton in UIScrollview
[btn release];
cnt++;
}
}
[mainRestaurantArray release];
counter++;
[self urlcalled]; //Is the method which call the webservice do the parsing and fills the mainRestaurantArray as a responce
}
The problem is, despite having added the abouve code, it takes much time to load, calls the web service like 10 times, and displays the images only then.
Can any one help me please?