UIController查看错误

时间:2016-04-25 07:49:56

标签: ios objective-c iphone uicollectionview

我创建了一个图像数组,CollectionView用于显示9个图像网格。但是在使用图像插座和CollectionView数组时出现错误。我按名称myImagemyDescriptionLabel为单元格内的图像和label分别声明了它。我通过评论来表明错误。

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

1 个答案:

答案 0 :(得分: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;
    }
相关问题