NSInvalidArgumentException原因:在试图显示Flickr图像时,数据参数在UITableView中为零

嗨在我的应用程序,我想在UITableView显示Flickr专辑列表,所以我已经search了很长时间,我已经find了一些解决scheme。 我已经使用了解决scheme中给出的方法,使其不能正常工作

 NSInvalidArgumentException', reason: 'data parameter is nil 

解决scheme链接点击这里

而且由于我第一次尝试这个,所以我无法解决这个问题。 这是Flickr的MY API LINK

我已经使用这个代码在UItableview显示Flickr图像专辑列表

 { NSMutableArray *photoURLs; NSMutableArray *photoSetNames; NSMutableArray *photoid1; } 

我的Flickr API密钥

 #define FlickrAPIKey @"a6a0c7d5efccffc285b0fe5ee1d938e3" - (void)viewDidLoad { [super viewDidLoad]; photoURLs = [[NSMutableArray alloc] init]; photoSetNames = [[NSMutableArray alloc] init]; photoid1 = [[NSMutableArray alloc] init]; [self loadFlickrPhotos]; } 

我的TableView代码

  - (void)loadFlickrPhotos { NSString *urlString = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=%@&user_id=%@&per_page=10&format=json&nojsoncallback=1", FlickrAPIKey, @"124757153@N04"]; NSURL *url = [NSURL URLWithString:urlString]; NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; NSArray *photosets = [[results objectForKey:@"photosets"] objectForKey:@"photoset"]; for (NSDictionary *photoset in photosets) { NSString *title = [[photoset objectForKey:@"title"] objectForKey:@"_content"]; [photoSetNames addObject:(title.length > 0 ? title : @"Untitled")]; NSString *photoid = [photoset objectForKey:@"id"]; [photoid1 addObject:photoid]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [photoSetNames count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier =@"Cell"; flickrpoliticalCell *cell =(flickrpoliticalCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[flickrpoliticalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.tit.text = [photoSetNames objectAtIndex:indexPath.row]; return cell; } 

尝试这个

 - (void)loadFlickrPhotos { // NSString *urlString = [NSString stringWithFormat:@"https://www.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=a6a0c7d5efccffc285b0fe5ee1d938e3&format=json&user_id=124757153@N04&per_page=10&nojsoncallback=1",nil]; NSLog(@"the url string==%@",urlString); NSURL *url = [NSURL URLWithString:urlString]; NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; NSLog(@"the str==%@",jsonString); NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; NSArray *photosets = [[results objectForKey:@"photosets"] objectForKey:@"photoset"]; for (NSDictionary *photoset in photosets) { NSString *title = [[photoset objectForKey:@"title"] objectForKey:@"_content"]; NSLog(@"title==%@",title); [photoSetNames addObject:(title.length > 0 ? title : @"Untitled")]; NSString *primary = [photoset objectForKey:@"primary"]; NSString *server = [photoset objectForKey:@"server"]; NSString *secret = [photoset objectForKey:@"secret"]; NSString *farm = [photoset objectForKey:@"farm"]; NSString *urlstr=[NSString stringWithFormat:@"http://farm%@.staticflickr.com/%@/%@_%@.jpg",farm,server,primary,secret]; NSLog(@"your photo id==%@",urlstr); [photoids addObject:urlstr]; } }