本文介绍了NSInvalidArgumentException原因:尝试显示Flickr图像时,UITableView中的数据参数为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想在UITableView
中显示Flickr
专辑列表,因此我已经搜索了很长时间,并且找到了一些解决方案.我使用了在解决方案中给出的方法,它无法正常工作,例如
Hi in my application I want to display the Flickr
album list in UITableView
so i have searched for long time and i have found some solution. I have used the method which given in the solution its not working its giving error like
NSInvalidArgumentException', reason: 'data parameter is nil
解决方案链接,请点击此处
而且由于我是第一次尝试,因此无法解决此问题.这是适用于Flickr的MY API链接
And since I'm trying this for first time I'm not able resolve this issue. This is MY API LINK for Flickr
我已使用此代码在UItableview
{
NSMutableArray *photoURLs;
NSMutableArray *photoSetNames;
NSMutableArray *photoid1;
}
我的Flickr API密钥
My Flickr API key
#define FlickrAPIKey @"a6a0c7d5efccffc285b0fe5ee1d938e3"
- (void)viewDidLoad
{
[super viewDidLoad];
photoURLs = [[NSMutableArray alloc] init];
photoSetNames = [[NSMutableArray alloc] init];
photoid1 = [[NSMutableArray alloc] init];
[self loadFlickrPhotos];
}
我的TableView代码
My TableView code
- (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];
}
}
这篇关于NSInvalidArgumentException原因:尝试显示Flickr图像时,UITableView中的数据参数为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!