ios - UICollectionViewCell unrecognized selector sent to instance -


i have created uicollectionviewcell looks this

#import "photocell.h"   @implementation photocell  @synthesize imageview;  - (instancetype)initwithframe:(cgrect)frame {     self = [super initwithframe:frame];     if (self)     {         self.backgroundcolor = [uicolor clearcolor];          imageview = [[uiimageview alloc] initwithframe:(cgrect){.origin = cgpointmake(4.0f, 4.0f), .size=cgrectinset(frame, 4.0f, 4.0f).size}];         imageview.autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight;         [self.contentview addsubview:imageview];     }     return self; }  @end 

i calling 1 of view controllers trying set uicollectionview.. calling class

- (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath; {     photocell *cell = (photocell *)[self.photocollectionview dequeuereusablecellwithreuseidentifier:@"cell" forindexpath:indexpath];      nsdictionary *currentphotodict = [imagearray objectatindex:indexpath.row];     uiimage *imageforcollection = [uiimage imagewithdata:[currentphotodict objectforkey:@"dimage"]];      // have no idea pass imag....      cell.imageview.image = imageforcollection;      return cell; } 

the issue is, getting error app falls on in heap.

 *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[uicollectionviewcell imageview]: unrecognized selector sent instance 0x16dc1a90' 

any fixing problem appreciated!

update:

i have created .nib file call aphotocell , have deleted uiview , added uiimageview.. have changed objects custom class photocell , can see iboutlet of uiimageview photocell have hooked up.. still reciving same error... hope makes sense... comments , answers below thought had fix... way continue watching tip , answers.

couple of things..

in photocell class - declare public property:

 @property (weak, nonatomic) iboutlet uiimageview *imageview; 

then in photocell xib (i assume you're creating from?) connect iboutlet created.

i think you're doing wrong in cellforitematindexpath - error shows instance of uicollectionviewcell doesn't respond cell.imageview.image = imageforcollection;

make sure cell identifier same put in storyboard / xib file rewrite cellforitematindexpath method this:

- (uicollectionviewcell *)collectionview:(uicollectionview *)cv cellforitematindexpath:(nsindexpath *)indexpath;{ photocell *cell = [ self.photocollectionview dequeuereusablecellwithreuseidentifier:@"correct cell identifier here" forindexpath:indexpath];  nsdictionary *currentphotodict = [imagearray objectatindex:indexpath.row]; uiimage *imageforcollection = [uiimage imagewithdata:[currentphotodict objectforkey:@"dimage"]];   cell.imageview.image = imageforcollection;  return cell; } 

edit

it seems created subclass of uicollectionviewcell , never created xib file it. since you're not using storyboards this:

in xcode:

create new file - select "user interface" left under 'ios' , select "empty" selection shows you.

after creating xib file - go , delete uiview there. object library on right, uicollectionview cell , drag onto view , drag uiimageview , place in uicollectionview cell.

now select uicollectionviewcell created , set class photocell class. connect iboutlets above. make sure set 'reusable cell' attribute too. important here.

then in viewcontroller loads uicollectionview - add viewdidload

        [photocollectionview registernib:[uinib nibwithnibname:@"the xib file name created eg: photocell" bundle:nil] forcellwithreuseidentifier:@"reuse identifier here"]; 

this should you.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -