ios - custom UICollectionView of UIImages error -


this first time have ever tried make uicollectionview before, have imagearray being read coredata.. of images nsdata reading them uiimage... display uiimage uicollectionview allow user select update preview view.

i have added these 3 delegates class.

and these delegates have implemented.

// add collectionview photocollectionview = [[uicollectionview alloc] initwithframe:cgrectmake(10.0, 50.0, 200.0, 700.0)];     [photocollectionview registerclass:[uicollectionviewcell class] forcellwithreuseidentifier:@"photocell"];     photocollectionview.datasource = self;     photocollectionview.delegate = self;     [self.view addsubview:photocollectionview];   //..  #pragma mark - collectionview delegates #pragma mark -- uicollectionview datasource - (nsinteger)collectionview:(uicollectionview *)view numberofitemsinsection:(nsinteger)section {     return [imagearray count]; }  - (nsinteger)numberofsectionsincollectionview: (uicollectionview *)collectionview {     return 1; }  - (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath {     uicollectionviewcell *cell = [cv dequeuereusablecellwithreuseidentifier:@"photocell" forindexpath:indexpath];     cell.backgroundcolor = [uicolor whitecolor];     return cell; }   #pragma mark -- uicollectionview delegate - (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath {     // todo: select item } - (void)collectionview:(uicollectionview *)collectionview diddeselectitematindexpath:(nsindexpath *)indexpath {     // todo: deselect item }   #pragma mark –- uicollectionviewdelegate flowlayout   - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath {     nsdictionary *currentphotodict = [imagearray objectatindex:indexpath.row];     uiimage *imageforcollection = [uiimage imagewithdata:[currentphotodict objectforkey:@"dimage"]];      //show image in collectionview?  }   - (uiedgeinsets)collectionview: (uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout insetforsectionatindex:(nsinteger)section {     return uiedgeinsetsmake(50, 20, 50, 20);  } 

when run code above reciving following error.

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'uicollectionview must initialized non-nil layout parameter' 

being first time have tried hoping give me tips or example code fix issue.

any appreciated.

the error stating need create collection view non-nil layout object.

you need use...

photocollectionview = [[uicollectionview alloc] initwithframe:cgrectmake(10.0, 50.0, 200.0, 700.0) collectionviewlayout:somelayoutobject]; 

you need create layout object first too.

possibly use...

photocollectionview = [[uicollectionview alloc] initwithframe:cgrectmake(10.0, 50.0, 200.0, 700.0) collectionviewlayout:[[uicollectionviewflowlayout alloc] init]]; 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -