イメージの配列を作成し、9イメージグリッドを表示するCollectionView
を作成しました。しかし、イメージアウトレットとCollectionView
アレイを使用している間にエラーがあります。セル内の画像にはmyImage
とmyDescriptionLabel
、画像内にはlabel
という名前で宣言しています。私はそれをコメントしてエラーを示しました。UIControllerビューエラー
CollectionViewController.h file :-
#import <UIKit/UIKit.h>
@interface CollectionViewController : UICollectionViewController
@property (strong, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (strong, nonatomic) IBOutlet UIImageView *myImage;
@property (strong, nonatomic) IBOutlet UILabel *myDescriptionLabel;
@end
CollectionViewController.h file :-
#import "CollectionViewController.h"
@interface CollectionViewController()
{
NSArray *arrayofImages;
NSArray *arrayofDescription;
}
@end
@implementation CollectionViewController
static NSString * const reuseIdentifier = @"Cell";
- (void)viewDidLoad {
[super viewDidLoad];
[[self myCollectionView]setDataSource:self];
[[self myCollectionView]setDelegate:self];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
arrayofImages=[[NSArray alloc]initWithObjects:@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpeg",@"8.jpg",@"10.jpg", nil];
arrayofDescription = [[NSArray alloc]initWithObjects:@"Image 1",@"Image 2",@"Image 3", @"Image 4",@"Image 5",@"Image 6", @"Image 7", @"Image 8",@"Image 9", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [arrayofDescription count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell myImage]setImage:[UIImage imageNamed:[arrayofImages object_getIndex:index.item]]];
[[cell myDescriptionLabel]setText:[arrayofDescription object_getIndex:IndexPath.item]];
// Here i Am getting error
return cell;
}
#pragma mark <UICollectionViewDelegate>
@end
可能あなたが私にテキストと画像の配列を表示するためのサンプルコードを送信してくださいすることができれば可能性があります。 –
こんにちは、私はあなたから提供するリンクからsoucecodeをダウンロードできます – PSS
'object_getIndex:'メソッドはどこに定義されていますか? – ThomasW