2012-03-30 10 views
1

で画像を表示するためのUITableViewを使用するために、私は(Webサービスから来ている)の画像を表示する画面で出力画像の下のように表示されていることを形式は、: -iphone + UIScrollViewのか、行列形式

enter image description here

私が実装したロジックは、uiscrollviewでイメージを追加したことです。以下のロジックと : -

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); 

Webサービスを行う機能は以下の通りです: -

-(void)urlcalled{ 
    @try 
    { 

     if (rangeDistance == nil) { 
      rangeDistance [email protected]"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); 
    } 

} 

しかし、私が直面しています問題は、画像が10回でループを完了した後に表示されています。 私は、webserviceから来るように画像を平行して表示したいので、時間が少なくて済むようにしてください。

私を助けてください。

+1

を作る.. – Narayana

+0

は、遅延ロードを試してみてください。リンゴniウェブサイトデモ – HarshIT

答えて

関連する問題