我是 iOS 新手,并尝试使用新的故事板功能将我的应用程序编写为纯 iOS 5 应用程序。
我想调用服务并显示 Collection View 上的所有图像。
所以,我需要保存图片、URL、点赞数、评论数和评论数。
你能帮我做这件事吗?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"cellID";
MyImageCollection *myCollection = (MyImageCollection *) [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
if (indexPath.section == 0)
{
myCollection.myImageView.image = [UIImage imageNamed:[natureImage objectAtIndex:indexPath.item]];
}
else
{
NSArray *arrayListg = [[NSArray alloc]initWithObjects:@"First Image URL",@"Second Image URL",@"Third Image URL",@"Forth Image URL", nil];
NSURL* url;
NSURLRequest* request;
for(int i = 0; i <4 ; i++)
{
url = [NSURL URLWithString:[arrayListg objectAtIndex:i]];
request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * data,
NSError * error) {
if (!error){
UIImage *image = [[UIImage alloc] initWithData:data];
myCollection.myImageView.image = image;
}
}
];
}
myCollection.myImageView.image = [UIImage imageNamed:[animalsImage objectAtIndex:indexPath.item]];
}
return myCollection;
}