kusumoto_teruya
kusumoto_teruya

Reputation: 2475

[CustomCell setImageView:]: unrecognized selector

I added UIImageView to CustomCell(subclass of UITableViewCell).
But, when I set an image on imageView on CustomCell,
the app clash with log message:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomCell setImageView:]: unrecognized selector sent to instance 0x10912d990'

I have this code.

ViewController

@property (nonatomic, strong) UITableView* tableView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 508)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* cellIdentifer = @"Cell";
    CustomCell* cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifer];
    if (cell == nil) {
        cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
    }
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    cell.imageView.image = [UIImage imageNamed:@"hello.jpg"];
                    break;
                default:
                    break;
            }
        default:
            break;
    }
    return cell;
}

CustomCell

@property (nonatomic, strong) UIImageView* imageView;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 310, 170)];
        [self addSubview:self.imageView];
    }
    return self;
}

Do you have any idea to add an image to imageView on customCell?
Thank you.

Upvotes: 0

Views: 114

Answers (4)

i think you have to do like something this... in

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (tableView==TABLE_MEMBERS)// && (count_cell%2==0))
        {

            Groupie_Moment_Timeline_Cell_Members *cell_mem =[tableView dequeueReusableCellWithIdentifier:@"Groupie_Moment_Timeline_Cell_Members"];

            if (cell_mem==nil)

            {
                NSArray *nibs=[[NSBundle mainBundle] loadNibNamed:@"Groupie_Moment_Timeline_Cell_Members" owner:self options:nil

    ];
                cell_mem=[nibs objectAtIndex:0];
            }




   cell_mem.selectionStyle=UITableViewCellSelectionStyleNone;
        [cell_small.IMG_TableImage setImage:[UIImage imageNamed:@"a.png"];
                return cell_small;

Upvotes: 0

kusumoto_teruya
kusumoto_teruya

Reputation: 2475

Thank you for many answers.I've resolved.

@property (nonatomic, strong) UIImageView* imageView;

@property (nonatomic, strong) UIImageView* myImageView;

Upvotes: 0

Eugene
Eugene

Reputation: 10045

What you're trying to do is to set your UITableViewCell's superclass readonly imageView property with this line self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 310, 170)];. You can't do that.

documentation: https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewCell/imageView

Upvotes: 2

penguinmaster
penguinmaster

Reputation: 151

@property (nonatomic, strong) UIImageView* imageView; should be in CustomCell.h not CustomCell.m so it's accessible from the other classes.

Upvotes: 0

Related Questions