您好我的应用程序尝试在我的Flickr
中显示UICollectionView
图像,但它显示了一个空的视图控件
我的代码显示Flickr
图片。
{
NSMutableArray *photoURLs;
NSMutableArray *photoSetNames;
NSMutableArray *photoids;
}
viewDidLoad
代码。
- (void)viewDidLoad
{
[super viewDidLoad];
photoURLs = [[NSMutableArray alloc] init];
photoSetNames = [[NSMutableArray alloc] init];
photoids = [[NSMutableArray alloc] init];
[self loadFlickrPhotos];
[self.collectionview reloadData];
}
- (void)loadFlickrPhotos {
NSString *urlString = [NSString stringWithFormat:@"https://www.flickr.com/services/rest/?method=flickr.photosets.getPhotos&format=json&api_key=a6a0c7d5efccffc285b0fe5ee1d938e3&photoset_id=72157644758906604&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];
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [photoids count];
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier =@"Cell";
imggpolitical *cell=(imggpolitical *) [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath: indexPath];
cell.imageview.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[photoids objectAtIndex:indexPath.row]]]]];
return cell;
}
我已使用上述内容在Flickr
中显示UICollectionView
图像,但它是一个空视图,请告诉我如何解决此问题。
感谢。
答案 0 :(得分:0)
尝试[self.collectionview reloadData]
答案 1 :(得分:0)
在 - (void)loadFlickrPhotos方法结束时,在UICollectionView上调用reloadData。您需要告诉UICollectionView刷新其数据。
答案 2 :(得分:0)
我没有看到您正在分配代理或数据源。或者就此而言,创建了您的UICollectionView。