2016-04-25 2 views
0

イメージの配列を作成し、9イメージグリッドを表示するCollectionViewを作成しました。しかし、イメージアウトレットとCollectionViewアレイを使用している間にエラーがあります。セル内の画像にはmyImagemyDescriptionLabel、画像内には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 
+0

可能あなたが私にテキストと画像の配列を表示するためのサンプルコードを送信してくださいすることができれば可能性があります。 –

+0

こんにちは、私はあなたから提供するリンクからsoucecodeをダウンロードできます – PSS

+0

'object_getIndex:'メソッドはどこに定義されていますか? – ThomasW

答えて

0

これはあなたがここで間違っていることも試してみてください -

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
     static NSString *cellIdentifier = @"Cell"; 
     UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 
     [[cell self.myImage]setImage:[UIImage imageNamed:[arrayofImages objectAtIndex:index.item]]]; 
     [[cell self.myDescriptionLabel]setText:[arrayofDescription objectAtIndex:IndexPath.item]]; 
     // Here i Am getting error 

     return cell; 
    } 
+0

まだ私は同じ問題を抱えています。 –

+0

エラーを投稿する –

+0

[[cell self.myImage] setImage:[UIImage imageNamed:[arrayofImages objectAtIndex:index.item]]]; [[cell self.myDescriptionLabel] setText:[arrayofDescription objectAtIndex:IndexPath.item]]; //エラーが発生する ']' –