私は iOS が初めてで、新しいストーリーボード機能を使用して純粋な iOS 5 アプリとしてアプリを作成しようとしています。
サービスを呼び出して、コレクション ビューに表示されるすべての画像を表示します。
そのため、画像、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;
}