ios - UIController View error -
i created array of images , collectionview
displaying 9 images grid. there error while using image outlet , collectionview
array.i declared name myimage
, mydescriptionlabel
image inside cell , label
respectively. have indicated error commenting it.
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 resources can 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 getting error return cell; } #pragma mark <uicollectionviewdelegate> @end
try may wrong here:-
- (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 getting error return cell; }
Comments
Post a Comment