I want to display the image(which comes from webservice) the format such that the output in the screen appears like below image:-
Now the logic i had implemented is,i had added the image in uiscrollview. with the below logic:-
for (int j=0;j<9;j++) {
for (int i=0; i<[mainRestaurantArray count];i++) {
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];
[btn release];
cnt++;
}
}
[mainRestaurantArray release];
counter++;
[self urlcalled];//The function which calls the webservice
}
//}
ScrlPhotos.contentSize = CGSizeMake(320, ([CombineArray count]/5.0)*60+25);
The function which does the webservice is below:-
-(void)urlcalled{
@try
{
if (rangeDistance == nil) {
rangeDistance =@"100";
}
urlstring[0]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Gym&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[1]=[NSString stringWithFormat:@"http://www.google.com/maps?q=resort&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[2]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Tourist place&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[3]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Hotels&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[4]=[NSString stringWithFormat:@"http://www.google.com/maps?q=shopping Mall&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[5]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Industries&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[6]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Shopping_mall&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[7]=[NSString stringWithFormat:@"http://www.google.com/maps?q=garden&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[8]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Religious Place&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
urlstring[9]=[NSString stringWithFormat:@"http://www.google.com/maps?q=Restaurants&sll=%@,%@&radius=200000&output=json",AppDel.Latitude,AppDel.Longitude];
NSLog(@"conte==>%d urlstring[counter]==>%@",counter,urlstring[counter]);
NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlstring[counter]]];
str1 = [str substringFromIndex:9];
//NSLog(@"===>%@",str1);
NSArray *array = [str1 componentsSeparatedByString:@"overlays:"];
NSString *str2 = [array objectAtIndex:1];
NSString *finalUpperStr = [str2 substringFromIndex:21];
array1 = [finalUpperStr componentsSeparatedByString:@"},panel:"];
NSString *strF = [array1 objectAtIndex:0];
NSArray *arrayF = [strF componentsSeparatedByString:@"{id:"];
///////....................this object will change as require in for loop .............................//
mainRestaurantArray = [[NSMutableArray alloc] init];
for (int i=1; i<[arrayF count]-5; i++) {
NSString *strF12 = [arrayF objectAtIndex:i];
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSArray *aryF23 = [strF12 componentsSeparatedByString:@"latlng:{"];
//NSLog(@"%@",[aryF23 objectAtIndex:1]);
NSString *strF23 = [aryF23 objectAtIndex:1];
NSArray *ar = [strF23 componentsSeparatedByString:@"},image:"];
//NSLog(@"%@",[ar objectAtIndex:0]);
NSString *strLat = [ar objectAtIndex:0];
NSArray *arrayLat = [strLat componentsSeparatedByString:@","];
NSString *strFLat = [[arrayLat objectAtIndex:0] substringFromIndex:4];
NSString *strLong = [[arrayLat objectAtIndex:1] substringFromIndex:4];
//NSLog(@"Lati = %@ Longi = %@" , strFLat , strLong);
[dic setValue:strFLat forKey:@"Latitude"];
[dic setValue:strLong forKey:@"Longitude"];
NSString *strLAdd = [ar objectAtIndex:1];
NSArray *arrayLAdd = [strLAdd componentsSeparatedByString:@"laddr:"];
//NSLog(@"%@",[arrayLAdd objectAtIndex:1]);
NSString *strLAdd1 = [arrayLAdd objectAtIndex:1];
NSArray *arrayLAdd1 = [strLAdd1 componentsSeparatedByString:@"geocode:"];
// NSLog(@"%@",[arrayLAdd1 objectAtIndex:0]);
NSString *strAddres = [[arrayLAdd1 objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
//NSLog(@"%@",strAddres);
[dic setValue:strAddres forKey:@"Address"];
NSString *strName = [arrayLAdd1 objectAtIndex:1];
NSArray *arrayName = [strName componentsSeparatedByString:@"name:"];
NSString *strName1 = [[arrayName objectAtIndex:1]stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSArray *arrayName1 = [strName1 componentsSeparatedByString:@"infoWindow:"];
[dic setValue:[arrayName1 objectAtIndex:0] forKey:@"Name"];
// for image load .. 07Dec..
NSString *strImage= [arrayF objectAtIndex:i];
NSRange range = [strImage rangeOfString:@"photoUrl"];
if(range.location == NSNotFound){
NSLog(@"Not found");
[dic setValue:@"" forKey:@"Image"];
}else{
NSArray *arrayImage = [strImage componentsSeparatedByString:@"photoUrl:"];
NSString *strImage1 = [arrayImage objectAtIndex:1];
NSArray *arrayImage1 = [strImage1 componentsSeparatedByString:@",photoType:"];
NSString *strfindImage = [[arrayImage1 objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
myImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strfindImage]]];
[dic setValue:myImage forKey:@"Image"];
}
[mainRestaurantArray addObject:dic];
if (i==20) {
break;
}
}
}
@catch (NSException * e)
{
NSLog(@"NSException==>%@",e);
}
}
But the problem i am facing is the image is displayed after completing the loop at 10 times. I want to display the image parallely as it comes from webservice,so that time taken should be less.. Is there any way out..
Please help me.