2013-12-11 23 views
0

我正在做一個flickr thingy 所以當我按下圖像時它會在新窗口中打開圖像。 到目前爲止,我已經得到它傳遞到下一個控制器的網址,但觀看正在使其崩潰。我有一個廈門國際銀行的「窗口」,其保持圖像視圖 我也用故事板試過,但不知何故,我不能得到它附加圖像視圖一次我把它... 這裏的一些代碼從新的xib中顯示圖像的nsstring中的圖像

FlickrGalleryViewController.m

- (void)loadFlickrPhotos 
{ 
photoURLs   = [[NSMutableArray alloc] init]; 
photoSmallImageData = [[NSMutableArray alloc] init]; 
photoURLsLargeImage = [[NSMutableArray alloc] init]; 

// 1. Build your Flickr API request w/Flickr API key in FlickrAPIKey.h 
NSString *urlString = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=%@&photoset_id=%@&format=json&nojsoncallback=1", FlickrAPIKey2, photoid]; 
NSURL *url = [NSURL URLWithString:urlString]; 
NSLog(@"url = %@", url); 
// 2. Get URLResponse string & parse JSON to Foundation objects. 
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; 
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; 
// 3. Pick thru results and build our arrays 
NSArray *photos = [[results objectForKey:@"photoset"] objectForKey:@"photo"]; 
for (NSDictionary *photo in photos) { 
    // 3.b Construct URL for e/ photo. 
    NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_s.jpg", [photo objectForKey:@"farm"], [photo objectForKey:@"server"], [photo objectForKey:@"id"], [photo objectForKey:@"secret"]]; 


    [photoURLs addObject:[NSURL URLWithString:photoURLString]]; 
    NSLog(@"%lu", (unsigned long)[photoURLs count]); 
    NSLog(@"photoURLString: %@", photoURLString); 

    [photoSmallImageData addObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoURLString]]]; 
    // Build and save the URL to the large image so we can zoom 
    // in on the image if requested 
    photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_m.jpg", 
    [photo objectForKey:@"farm"], [photo objectForKey:@"server"], 
    [photo objectForKey:@"id"], [photo objectForKey:@"secret"]]; 

    [photoURLsLargeImage addObject:[NSURL URLWithString:photoURLString]]; 

    NSLog(@"photoURLsLareImage: %@\n\n", photoURLString); 
} 
} 

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSLog(@"didselect"); 
    flickerImageViewController *viewControllerB = [[flickerImageViewController alloc] initWithNibName:@"flickerImageViewController" bundle:nil]; 
    viewControllerB.photoLargeInfo = [photoURLsLargeImage objectAtIndex:indexPath.row]; 
    [self.navigationController pushViewController:viewControllerB animated:YES]; 
} 

flickerImageViewController.m 這裏是我的問題。當我在flickrImage上設置斷點時。它的顯示flickrImage是零和photoLargeInfo有一個網址。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    flickrImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoLargeInfo]]]; 



} 

(LLDB)PO flickrImage.image 零 (LLDB)

(LLDB)PO photoLargeInfo http://farm4.static.flickr.com/3803/10798724923_e5c539a520_m.jpg (LLDB)

這裏就是它扔在我的錯誤

*終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「 - [NSURL長]:無法識別的選擇發送到實例0xb2dbf70」

+0

請檢查您的圖片url是否在使用NSLOG(@「photoLargeInfo%@」,photoLargeInfo)的其他控制器中獲取。 –

+0

它顯示了這個:photoLargeInfo http://farm4.static.flickr.com/3803/10798724923_e5c539a520_m.jpg – KennyVB

+0

k但鏈接中的http://,我認爲如果你傳遞一個url,它應該以http開頭://或https:// –

回答

1

photoURLsLargeImage數組包含NSURL不NSString的

所以最好做photoLargeInfo到NSURL類型和在.M使用

在.H

@property(nonatomic, strong) NSURL *photoLargeInfo; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    flickrImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:photoLargeInfo]]; 
}