UICollectionViewCell unrecognized selector sent to instance











up vote
4
down vote

favorite












I have created a UICollectionViewCell that looks like 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 am calling this from one of my view controllers where I am trying to set up a UICollectionView.. this is where I am calling this 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"]];

// but I have no idea where to pass the imag....

cell.imageView.image = imageForCollection;

return cell;
}


The issue is, I am getting this error then my app falls over in a heap.



 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance 0x16dc1a90'


Update



I have created a .nib file call aPhotoCell and I have deleted the UIView from it and added a UIImageView. I have then changed the objects Custom Class to PhotoCell and now that I can see the IBOutlet of UIImageView from PhotoCell I have hooked that up, but still I am receiving the same error. From the comments and answers below, this is what I thought I had to do to fix.










share|improve this question




















  • 1




    seems like the delegate method -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath is not returning PhotoCell object
    – bhawesh
    Mar 25 '14 at 8:23















up vote
4
down vote

favorite












I have created a UICollectionViewCell that looks like 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 am calling this from one of my view controllers where I am trying to set up a UICollectionView.. this is where I am calling this 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"]];

// but I have no idea where to pass the imag....

cell.imageView.image = imageForCollection;

return cell;
}


The issue is, I am getting this error then my app falls over in a heap.



 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance 0x16dc1a90'


Update



I have created a .nib file call aPhotoCell and I have deleted the UIView from it and added a UIImageView. I have then changed the objects Custom Class to PhotoCell and now that I can see the IBOutlet of UIImageView from PhotoCell I have hooked that up, but still I am receiving the same error. From the comments and answers below, this is what I thought I had to do to fix.










share|improve this question




















  • 1




    seems like the delegate method -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath is not returning PhotoCell object
    – bhawesh
    Mar 25 '14 at 8:23













up vote
4
down vote

favorite









up vote
4
down vote

favorite











I have created a UICollectionViewCell that looks like 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 am calling this from one of my view controllers where I am trying to set up a UICollectionView.. this is where I am calling this 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"]];

// but I have no idea where to pass the imag....

cell.imageView.image = imageForCollection;

return cell;
}


The issue is, I am getting this error then my app falls over in a heap.



 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance 0x16dc1a90'


Update



I have created a .nib file call aPhotoCell and I have deleted the UIView from it and added a UIImageView. I have then changed the objects Custom Class to PhotoCell and now that I can see the IBOutlet of UIImageView from PhotoCell I have hooked that up, but still I am receiving the same error. From the comments and answers below, this is what I thought I had to do to fix.










share|improve this question















I have created a UICollectionViewCell that looks like 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 am calling this from one of my view controllers where I am trying to set up a UICollectionView.. this is where I am calling this 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"]];

// but I have no idea where to pass the imag....

cell.imageView.image = imageForCollection;

return cell;
}


The issue is, I am getting this error then my app falls over in a heap.



 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell imageView]: unrecognized selector sent to instance 0x16dc1a90'


Update



I have created a .nib file call aPhotoCell and I have deleted the UIView from it and added a UIImageView. I have then changed the objects Custom Class to PhotoCell and now that I can see the IBOutlet of UIImageView from PhotoCell I have hooked that up, but still I am receiving the same error. From the comments and answers below, this is what I thought I had to do to fix.







ios objective-c uicollectionview uicollectionviewcell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 22:59









halfer

14.3k758108




14.3k758108










asked Mar 25 '14 at 8:14









HurkNburkS

2,3071683162




2,3071683162








  • 1




    seems like the delegate method -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath is not returning PhotoCell object
    – bhawesh
    Mar 25 '14 at 8:23














  • 1




    seems like the delegate method -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath is not returning PhotoCell object
    – bhawesh
    Mar 25 '14 at 8:23








1




1




seems like the delegate method -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath is not returning PhotoCell object
– bhawesh
Mar 25 '14 at 8:23




seems like the delegate method -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath is not returning PhotoCell object
– bhawesh
Mar 25 '14 at 8:23












5 Answers
5






active

oldest

votes

















up vote
5
down vote



accepted










Couple of things..



In your PhotoCell class - declare a public property:



 @property (weak, nonatomic) IBOutlet UIImageView *imageView;


Then in your PhotoCell xib (I assume this is where you're creating it from?) connect it to the IBOutLet you created.



I think you're doing something wrong in your cellForItemAtIndexPath - as your error shows an instance of UICollectionViewCell doesn't respond to cell.imageView.image = imageForCollection;



Make sure your cell identifier is also the same as you put it in your storyboard / xib file
Rewrite your cellForItemAtIndexPath method like 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 like you created a subclass of UICollectionViewCell and never created a xib file for it. Since you're not using storyboards do this:



In Xcode:



Create a new file - select "User Interface" from the left under 'iOS' and select "empty" from the selection it shows you.



After creating your xib file - go to it and delete UIView that is there. Then from the object library on your right, look for UICollectionView Cell and drag it onto the view and then drag a UIImageView and place it in your UICollectionView cell.



Now select UICollectionViewCell you just created and set its class to the PhotoCell class. Connect your IBOutlets like above.
Make sure to set the 'Reusable Cell' attribute too. Its important here.



Then in the viewController that loads your UICollectionView - add this to viewDidLoad



        [photoCollectionView registerNib:[UINib nibWithNibName:@"THE XIB FILE NAME YOU JUST CREATED eg: PhotoCell" bundle:nil] forCellWithReuseIdentifier:@"REUSE IDENTIFIER HERE"];


This should help you.






share|improve this answer























  • I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
    – HurkNburkS
    Mar 25 '14 at 8:28










  • I'll update my answer..
    – Robert J. Clegg
    Mar 25 '14 at 8:29










  • thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
    – HurkNburkS
    Mar 25 '14 at 8:31










  • Answer updated. Let me know if you get stuck.
    – Robert J. Clegg
    Mar 25 '14 at 8:38










  • CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
    – HurkNburkS
    Mar 25 '14 at 8:44


















up vote
4
down vote













I also had this problem and my issue was that I had an error in my code in another place.



I used this code to register the the UICollectionViewCell in the viewDidLoad method.



[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseLabel"];


However, when I tried to update the cell with my custom UICollectionViewCell I didn't change this line to work my custom cell. So I changed the code to this:



[self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"reuseLabel"];





share|improve this answer




























    up vote
    0
    down vote














    1. According to UICollectionView Class Reference,
      CollectionViewCell just didn't have imageView property. You should add it to cell's contentView in Storyboard / in code first.


    2. Also, You're using own PhotoCell class. Check that your cell have correct class name in Storyboard.







    share|improve this answer





















    • I dont have a story board.... what should I do?
      – HurkNburkS
      Mar 25 '14 at 8:26


















    up vote
    0
    down vote













    I assume the cell identified by "cell" is defined in a Xib file. If so, I suspect that the error is because the main view in the Xib file is defined with the UICollectionViewCell class instead of your custom PhotoCell class.



    EDIT:

    After learning that you're not using xib or storyboards, what happens is that dequeueReusableCellWithReuseIdentifier doesn't find any cell with the given identifier "cell" becouse you haven't defined it anywhere. From the documentation:




    You must register a class or nib file using the
    registerNib:forCellReuseIdentifier: or
    registerClass:forCellReuseIdentifier: method before calling this
    method.




    In your case you should use registerClass:... to register your class with the "cell" or any other identifier.






    share|improve this answer























    • I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
      – HurkNburkS
      Mar 25 '14 at 8:27










    • See edited answer!
      – Merlevede
      Mar 25 '14 at 8:35


















    up vote
    0
    down vote













    PhotoCell xib file need set "cell" in Identifier
    Your code should be:



    - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
    {
    PhotoCell *cell = (PhotoCell *)[self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (cell == nil) {
    // Load the top-level objects from the custom cell XIB.
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cell" owner:self options:nil];
    // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
    cell = [topLevelObjects objectAtIndex:0];
    }
    NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
    UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];

    // but I have no idea where to pass the imag....

    cell.imageView.image = imageForCollection;

    return cell;


    }






    share|improve this answer























    • I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
      – HurkNburkS
      Mar 25 '14 at 8:33










    • I have updated my answer.
      – HoanNguyen
      Mar 25 '14 at 8:40











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22628749%2fuicollectionviewcell-unrecognized-selector-sent-to-instance%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote



    accepted










    Couple of things..



    In your PhotoCell class - declare a public property:



     @property (weak, nonatomic) IBOutlet UIImageView *imageView;


    Then in your PhotoCell xib (I assume this is where you're creating it from?) connect it to the IBOutLet you created.



    I think you're doing something wrong in your cellForItemAtIndexPath - as your error shows an instance of UICollectionViewCell doesn't respond to cell.imageView.image = imageForCollection;



    Make sure your cell identifier is also the same as you put it in your storyboard / xib file
    Rewrite your cellForItemAtIndexPath method like 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 like you created a subclass of UICollectionViewCell and never created a xib file for it. Since you're not using storyboards do this:



    In Xcode:



    Create a new file - select "User Interface" from the left under 'iOS' and select "empty" from the selection it shows you.



    After creating your xib file - go to it and delete UIView that is there. Then from the object library on your right, look for UICollectionView Cell and drag it onto the view and then drag a UIImageView and place it in your UICollectionView cell.



    Now select UICollectionViewCell you just created and set its class to the PhotoCell class. Connect your IBOutlets like above.
    Make sure to set the 'Reusable Cell' attribute too. Its important here.



    Then in the viewController that loads your UICollectionView - add this to viewDidLoad



            [photoCollectionView registerNib:[UINib nibWithNibName:@"THE XIB FILE NAME YOU JUST CREATED eg: PhotoCell" bundle:nil] forCellWithReuseIdentifier:@"REUSE IDENTIFIER HERE"];


    This should help you.






    share|improve this answer























    • I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
      – HurkNburkS
      Mar 25 '14 at 8:28










    • I'll update my answer..
      – Robert J. Clegg
      Mar 25 '14 at 8:29










    • thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
      – HurkNburkS
      Mar 25 '14 at 8:31










    • Answer updated. Let me know if you get stuck.
      – Robert J. Clegg
      Mar 25 '14 at 8:38










    • CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
      – HurkNburkS
      Mar 25 '14 at 8:44















    up vote
    5
    down vote



    accepted










    Couple of things..



    In your PhotoCell class - declare a public property:



     @property (weak, nonatomic) IBOutlet UIImageView *imageView;


    Then in your PhotoCell xib (I assume this is where you're creating it from?) connect it to the IBOutLet you created.



    I think you're doing something wrong in your cellForItemAtIndexPath - as your error shows an instance of UICollectionViewCell doesn't respond to cell.imageView.image = imageForCollection;



    Make sure your cell identifier is also the same as you put it in your storyboard / xib file
    Rewrite your cellForItemAtIndexPath method like 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 like you created a subclass of UICollectionViewCell and never created a xib file for it. Since you're not using storyboards do this:



    In Xcode:



    Create a new file - select "User Interface" from the left under 'iOS' and select "empty" from the selection it shows you.



    After creating your xib file - go to it and delete UIView that is there. Then from the object library on your right, look for UICollectionView Cell and drag it onto the view and then drag a UIImageView and place it in your UICollectionView cell.



    Now select UICollectionViewCell you just created and set its class to the PhotoCell class. Connect your IBOutlets like above.
    Make sure to set the 'Reusable Cell' attribute too. Its important here.



    Then in the viewController that loads your UICollectionView - add this to viewDidLoad



            [photoCollectionView registerNib:[UINib nibWithNibName:@"THE XIB FILE NAME YOU JUST CREATED eg: PhotoCell" bundle:nil] forCellWithReuseIdentifier:@"REUSE IDENTIFIER HERE"];


    This should help you.






    share|improve this answer























    • I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
      – HurkNburkS
      Mar 25 '14 at 8:28










    • I'll update my answer..
      – Robert J. Clegg
      Mar 25 '14 at 8:29










    • thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
      – HurkNburkS
      Mar 25 '14 at 8:31










    • Answer updated. Let me know if you get stuck.
      – Robert J. Clegg
      Mar 25 '14 at 8:38










    • CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
      – HurkNburkS
      Mar 25 '14 at 8:44













    up vote
    5
    down vote



    accepted







    up vote
    5
    down vote



    accepted






    Couple of things..



    In your PhotoCell class - declare a public property:



     @property (weak, nonatomic) IBOutlet UIImageView *imageView;


    Then in your PhotoCell xib (I assume this is where you're creating it from?) connect it to the IBOutLet you created.



    I think you're doing something wrong in your cellForItemAtIndexPath - as your error shows an instance of UICollectionViewCell doesn't respond to cell.imageView.image = imageForCollection;



    Make sure your cell identifier is also the same as you put it in your storyboard / xib file
    Rewrite your cellForItemAtIndexPath method like 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 like you created a subclass of UICollectionViewCell and never created a xib file for it. Since you're not using storyboards do this:



    In Xcode:



    Create a new file - select "User Interface" from the left under 'iOS' and select "empty" from the selection it shows you.



    After creating your xib file - go to it and delete UIView that is there. Then from the object library on your right, look for UICollectionView Cell and drag it onto the view and then drag a UIImageView and place it in your UICollectionView cell.



    Now select UICollectionViewCell you just created and set its class to the PhotoCell class. Connect your IBOutlets like above.
    Make sure to set the 'Reusable Cell' attribute too. Its important here.



    Then in the viewController that loads your UICollectionView - add this to viewDidLoad



            [photoCollectionView registerNib:[UINib nibWithNibName:@"THE XIB FILE NAME YOU JUST CREATED eg: PhotoCell" bundle:nil] forCellWithReuseIdentifier:@"REUSE IDENTIFIER HERE"];


    This should help you.






    share|improve this answer














    Couple of things..



    In your PhotoCell class - declare a public property:



     @property (weak, nonatomic) IBOutlet UIImageView *imageView;


    Then in your PhotoCell xib (I assume this is where you're creating it from?) connect it to the IBOutLet you created.



    I think you're doing something wrong in your cellForItemAtIndexPath - as your error shows an instance of UICollectionViewCell doesn't respond to cell.imageView.image = imageForCollection;



    Make sure your cell identifier is also the same as you put it in your storyboard / xib file
    Rewrite your cellForItemAtIndexPath method like 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 like you created a subclass of UICollectionViewCell and never created a xib file for it. Since you're not using storyboards do this:



    In Xcode:



    Create a new file - select "User Interface" from the left under 'iOS' and select "empty" from the selection it shows you.



    After creating your xib file - go to it and delete UIView that is there. Then from the object library on your right, look for UICollectionView Cell and drag it onto the view and then drag a UIImageView and place it in your UICollectionView cell.



    Now select UICollectionViewCell you just created and set its class to the PhotoCell class. Connect your IBOutlets like above.
    Make sure to set the 'Reusable Cell' attribute too. Its important here.



    Then in the viewController that loads your UICollectionView - add this to viewDidLoad



            [photoCollectionView registerNib:[UINib nibWithNibName:@"THE XIB FILE NAME YOU JUST CREATED eg: PhotoCell" bundle:nil] forCellWithReuseIdentifier:@"REUSE IDENTIFIER HERE"];


    This should help you.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 2 '15 at 19:47

























    answered Mar 25 '14 at 8:27









    Robert J. Clegg

    4,02663176




    4,02663176












    • I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
      – HurkNburkS
      Mar 25 '14 at 8:28










    • I'll update my answer..
      – Robert J. Clegg
      Mar 25 '14 at 8:29










    • thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
      – HurkNburkS
      Mar 25 '14 at 8:31










    • Answer updated. Let me know if you get stuck.
      – Robert J. Clegg
      Mar 25 '14 at 8:38










    • CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
      – HurkNburkS
      Mar 25 '14 at 8:44


















    • I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
      – HurkNburkS
      Mar 25 '14 at 8:28










    • I'll update my answer..
      – Robert J. Clegg
      Mar 25 '14 at 8:29










    • thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
      – HurkNburkS
      Mar 25 '14 at 8:31










    • Answer updated. Let me know if you get stuck.
      – Robert J. Clegg
      Mar 25 '14 at 8:38










    • CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
      – HurkNburkS
      Mar 25 '14 at 8:44
















    I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
    – HurkNburkS
    Mar 25 '14 at 8:28




    I dont have a story board or nib for this class.. when I created it i was not give an option to make one with it.. Im not really sure how to proceed with that.
    – HurkNburkS
    Mar 25 '14 at 8:28












    I'll update my answer..
    – Robert J. Clegg
    Mar 25 '14 at 8:29




    I'll update my answer..
    – Robert J. Clegg
    Mar 25 '14 at 8:29












    thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
    – HurkNburkS
    Mar 25 '14 at 8:31




    thanks.. the thing is I have tried creating an xib then connecting it using custom class and connecting the IBOutlet but I still recive the same error.
    – HurkNburkS
    Mar 25 '14 at 8:31












    Answer updated. Let me know if you get stuck.
    – Robert J. Clegg
    Mar 25 '14 at 8:38




    Answer updated. Let me know if you get stuck.
    – Robert J. Clegg
    Mar 25 '14 at 8:38












    CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
    – HurkNburkS
    Mar 25 '14 at 8:44




    CHAMP!!! thanks a MEGATON! lol so I was almost there instead of using a UICollectionViewCell then adding the Imageview I was just trying to do it with the imageview! this worked perfectly!!! thnks a ton seriouslY! been banging my head against the wall! again many thanks! lol
    – HurkNburkS
    Mar 25 '14 at 8:44












    up vote
    4
    down vote













    I also had this problem and my issue was that I had an error in my code in another place.



    I used this code to register the the UICollectionViewCell in the viewDidLoad method.



    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseLabel"];


    However, when I tried to update the cell with my custom UICollectionViewCell I didn't change this line to work my custom cell. So I changed the code to this:



    [self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"reuseLabel"];





    share|improve this answer

























      up vote
      4
      down vote













      I also had this problem and my issue was that I had an error in my code in another place.



      I used this code to register the the UICollectionViewCell in the viewDidLoad method.



      [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseLabel"];


      However, when I tried to update the cell with my custom UICollectionViewCell I didn't change this line to work my custom cell. So I changed the code to this:



      [self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"reuseLabel"];





      share|improve this answer























        up vote
        4
        down vote










        up vote
        4
        down vote









        I also had this problem and my issue was that I had an error in my code in another place.



        I used this code to register the the UICollectionViewCell in the viewDidLoad method.



        [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseLabel"];


        However, when I tried to update the cell with my custom UICollectionViewCell I didn't change this line to work my custom cell. So I changed the code to this:



        [self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"reuseLabel"];





        share|improve this answer












        I also had this problem and my issue was that I had an error in my code in another place.



        I used this code to register the the UICollectionViewCell in the viewDidLoad method.



        [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseLabel"];


        However, when I tried to update the cell with my custom UICollectionViewCell I didn't change this line to work my custom cell. So I changed the code to this:



        [self.collectionView registerClass:[MyCustomCell class] forCellWithReuseIdentifier:@"reuseLabel"];






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 4 '16 at 14:35









        Rabs G

        628711




        628711






















            up vote
            0
            down vote














            1. According to UICollectionView Class Reference,
              CollectionViewCell just didn't have imageView property. You should add it to cell's contentView in Storyboard / in code first.


            2. Also, You're using own PhotoCell class. Check that your cell have correct class name in Storyboard.







            share|improve this answer





















            • I dont have a story board.... what should I do?
              – HurkNburkS
              Mar 25 '14 at 8:26















            up vote
            0
            down vote














            1. According to UICollectionView Class Reference,
              CollectionViewCell just didn't have imageView property. You should add it to cell's contentView in Storyboard / in code first.


            2. Also, You're using own PhotoCell class. Check that your cell have correct class name in Storyboard.







            share|improve this answer





















            • I dont have a story board.... what should I do?
              – HurkNburkS
              Mar 25 '14 at 8:26













            up vote
            0
            down vote










            up vote
            0
            down vote










            1. According to UICollectionView Class Reference,
              CollectionViewCell just didn't have imageView property. You should add it to cell's contentView in Storyboard / in code first.


            2. Also, You're using own PhotoCell class. Check that your cell have correct class name in Storyboard.







            share|improve this answer













            1. According to UICollectionView Class Reference,
              CollectionViewCell just didn't have imageView property. You should add it to cell's contentView in Storyboard / in code first.


            2. Also, You're using own PhotoCell class. Check that your cell have correct class name in Storyboard.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 '14 at 8:21









            Tim

            7915




            7915












            • I dont have a story board.... what should I do?
              – HurkNburkS
              Mar 25 '14 at 8:26


















            • I dont have a story board.... what should I do?
              – HurkNburkS
              Mar 25 '14 at 8:26
















            I dont have a story board.... what should I do?
            – HurkNburkS
            Mar 25 '14 at 8:26




            I dont have a story board.... what should I do?
            – HurkNburkS
            Mar 25 '14 at 8:26










            up vote
            0
            down vote













            I assume the cell identified by "cell" is defined in a Xib file. If so, I suspect that the error is because the main view in the Xib file is defined with the UICollectionViewCell class instead of your custom PhotoCell class.



            EDIT:

            After learning that you're not using xib or storyboards, what happens is that dequeueReusableCellWithReuseIdentifier doesn't find any cell with the given identifier "cell" becouse you haven't defined it anywhere. From the documentation:




            You must register a class or nib file using the
            registerNib:forCellReuseIdentifier: or
            registerClass:forCellReuseIdentifier: method before calling this
            method.




            In your case you should use registerClass:... to register your class with the "cell" or any other identifier.






            share|improve this answer























            • I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
              – HurkNburkS
              Mar 25 '14 at 8:27










            • See edited answer!
              – Merlevede
              Mar 25 '14 at 8:35















            up vote
            0
            down vote













            I assume the cell identified by "cell" is defined in a Xib file. If so, I suspect that the error is because the main view in the Xib file is defined with the UICollectionViewCell class instead of your custom PhotoCell class.



            EDIT:

            After learning that you're not using xib or storyboards, what happens is that dequeueReusableCellWithReuseIdentifier doesn't find any cell with the given identifier "cell" becouse you haven't defined it anywhere. From the documentation:




            You must register a class or nib file using the
            registerNib:forCellReuseIdentifier: or
            registerClass:forCellReuseIdentifier: method before calling this
            method.




            In your case you should use registerClass:... to register your class with the "cell" or any other identifier.






            share|improve this answer























            • I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
              – HurkNburkS
              Mar 25 '14 at 8:27










            • See edited answer!
              – Merlevede
              Mar 25 '14 at 8:35













            up vote
            0
            down vote










            up vote
            0
            down vote









            I assume the cell identified by "cell" is defined in a Xib file. If so, I suspect that the error is because the main view in the Xib file is defined with the UICollectionViewCell class instead of your custom PhotoCell class.



            EDIT:

            After learning that you're not using xib or storyboards, what happens is that dequeueReusableCellWithReuseIdentifier doesn't find any cell with the given identifier "cell" becouse you haven't defined it anywhere. From the documentation:




            You must register a class or nib file using the
            registerNib:forCellReuseIdentifier: or
            registerClass:forCellReuseIdentifier: method before calling this
            method.




            In your case you should use registerClass:... to register your class with the "cell" or any other identifier.






            share|improve this answer














            I assume the cell identified by "cell" is defined in a Xib file. If so, I suspect that the error is because the main view in the Xib file is defined with the UICollectionViewCell class instead of your custom PhotoCell class.



            EDIT:

            After learning that you're not using xib or storyboards, what happens is that dequeueReusableCellWithReuseIdentifier doesn't find any cell with the given identifier "cell" becouse you haven't defined it anywhere. From the documentation:




            You must register a class or nib file using the
            registerNib:forCellReuseIdentifier: or
            registerClass:forCellReuseIdentifier: method before calling this
            method.




            In your case you should use registerClass:... to register your class with the "cell" or any other identifier.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 25 '14 at 8:35

























            answered Mar 25 '14 at 8:23









            Merlevede

            7,41511637




            7,41511637












            • I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
              – HurkNburkS
              Mar 25 '14 at 8:27










            • See edited answer!
              – Merlevede
              Mar 25 '14 at 8:35


















            • I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
              – HurkNburkS
              Mar 25 '14 at 8:27










            • See edited answer!
              – Merlevede
              Mar 25 '14 at 8:35
















            I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
            – HurkNburkS
            Mar 25 '14 at 8:27




            I dont have an xib file for this class as UICOllectionViewCell's dont have xibs when you create them.. nore do they allow you to add them so i dont know what to do??
            – HurkNburkS
            Mar 25 '14 at 8:27












            See edited answer!
            – Merlevede
            Mar 25 '14 at 8:35




            See edited answer!
            – Merlevede
            Mar 25 '14 at 8:35










            up vote
            0
            down vote













            PhotoCell xib file need set "cell" in Identifier
            Your code should be:



            - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
            {
            PhotoCell *cell = (PhotoCell *)[self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
            if (cell == nil) {
            // Load the top-level objects from the custom cell XIB.
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cell" owner:self options:nil];
            // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
            cell = [topLevelObjects objectAtIndex:0];
            }
            NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
            UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];

            // but I have no idea where to pass the imag....

            cell.imageView.image = imageForCollection;

            return cell;


            }






            share|improve this answer























            • I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
              – HurkNburkS
              Mar 25 '14 at 8:33










            • I have updated my answer.
              – HoanNguyen
              Mar 25 '14 at 8:40















            up vote
            0
            down vote













            PhotoCell xib file need set "cell" in Identifier
            Your code should be:



            - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
            {
            PhotoCell *cell = (PhotoCell *)[self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
            if (cell == nil) {
            // Load the top-level objects from the custom cell XIB.
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cell" owner:self options:nil];
            // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
            cell = [topLevelObjects objectAtIndex:0];
            }
            NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
            UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];

            // but I have no idea where to pass the imag....

            cell.imageView.image = imageForCollection;

            return cell;


            }






            share|improve this answer























            • I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
              – HurkNburkS
              Mar 25 '14 at 8:33










            • I have updated my answer.
              – HoanNguyen
              Mar 25 '14 at 8:40













            up vote
            0
            down vote










            up vote
            0
            down vote









            PhotoCell xib file need set "cell" in Identifier
            Your code should be:



            - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
            {
            PhotoCell *cell = (PhotoCell *)[self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
            if (cell == nil) {
            // Load the top-level objects from the custom cell XIB.
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cell" owner:self options:nil];
            // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
            cell = [topLevelObjects objectAtIndex:0];
            }
            NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
            UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];

            // but I have no idea where to pass the imag....

            cell.imageView.image = imageForCollection;

            return cell;


            }






            share|improve this answer














            PhotoCell xib file need set "cell" in Identifier
            Your code should be:



            - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
            {
            PhotoCell *cell = (PhotoCell *)[self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
            if (cell == nil) {
            // Load the top-level objects from the custom cell XIB.
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cell" owner:self options:nil];
            // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
            cell = [topLevelObjects objectAtIndex:0];
            }
            NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
            UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];

            // but I have no idea where to pass the imag....

            cell.imageView.image = imageForCollection;

            return cell;


            }







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 25 '14 at 8:40

























            answered Mar 25 '14 at 8:31









            HoanNguyen

            360111




            360111












            • I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
              – HurkNburkS
              Mar 25 '14 at 8:33










            • I have updated my answer.
              – HoanNguyen
              Mar 25 '14 at 8:40


















            • I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
              – HurkNburkS
              Mar 25 '14 at 8:33










            • I have updated my answer.
              – HoanNguyen
              Mar 25 '14 at 8:40
















            I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
            – HurkNburkS
            Mar 25 '14 at 8:33




            I have now created a nib file changes its customclass to PhotoCell and hooked up the UIImageView IBOutlet I made. and still I recive the same error... I am looking for more ideas now.
            – HurkNburkS
            Mar 25 '14 at 8:33












            I have updated my answer.
            – HoanNguyen
            Mar 25 '14 at 8:40




            I have updated my answer.
            – HoanNguyen
            Mar 25 '14 at 8:40


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22628749%2fuicollectionviewcell-unrecognized-selector-sent-to-instance%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma