2014-09-06 3 views
1

Я пытаюсь выяснить, как получить MWphotobrowser, чтобы получить фотографию, фотографию, миниатюру фотографии и т. Д. Из json-файла extermal-сервера.MWphotobrowser - Fetch Images от Json

В viewDidLoad, у меня есть этот код:

- (void)viewDidLoad { 

NSURL *url = [NSURL URLWithString:@"https://s3.amazonaws.com/mobile-makers-lib/superheroes.json"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

[super viewDidLoad]; 

[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) 

{ 

    NSLog(@"Back from the web"); 
}]; 

NSLog(@"Just made the web call"); 

} 

В Menu.m Вопрос 3 MWphotobrowser, я следующий код:

case 3: { 

     photo.caption = [self.result valueForKeyPath:@"name"]; 

     NSArray * photoURLs = [self.result valueForKeyPath:@"avatar_url"]; 
     NSString * imageURL = [photoURLs objectAtIndex:indexPath.row]; 

     [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:imageURL]]]; 



     enableGrid = NO; 
     break; 

    } 

Incase вы пропустили его, файл в формате JSON Я используя https://s3.amazonaws.com/mobile-makers-lib/superheroes.json

Ничего, что я настраиваю, похоже, заставляет его работать, любые идеи, как это исправить?

+0

, что результат u получить в self.result –

+0

Фактически ур результат исходит из [array {dictionary}] format, thats y i спросил –

+0

Да. В Menu.h у меня есть @property (неатомный, сильный) результат NSMutableDictionary *; Неправильно? – HalesEnchanted

ответ

0
[NSURLConnection sendAsynchronousRequest:request 
           queue:[NSOperationQueue mainQueue] 
        completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) 

{ 

    // here make sure ur response is getting or not 

    if ([data length] >0 && connectionError == nil) 
    { 

     // DO YOUR WORK HERE 


      self.superheroes = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &connectionError]; 

      NSLog(@"data downloaded.==%@", self.superheroes); 

    } 
    else if ([data length] == 0 && connectionError == nil) 
    { 
     NSLog(@"Nothing was downloaded."); 
    } 
    else if (connectionError != nil){ 
     NSLog(@"Error = %@", connectionError); 
    } 



    }]; 

здесь ур получения ответа от сервера NSArray --> NSMutableDictionary` так

Case сценарий

case 3: { 


     NSDictionary *superhero = [self.superheroes objectAtIndex:indexPath.row]; 




     photo.caption = superhero[@"name"]; 

     NSString * imageURL = superhero[@"avatar_url"]; 

     // NSArray * photoURLs = superhero[@"avatar_url"]; 


     [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:imageURL]]]; 




     enableGrid = NO; 
     break; 

    } 

ур окончательный из пут

enter image description here

+0

имеют счастливый день frnd, –