user1597244
user1597244

Reputation: 39

UIImageview set image crash

I'm setting image to a UIImageView using in the below code

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    for(int i=0;i<[radioButtons count];i++){
        [[radioButtons objectAtIndex:i] setImage:[UIImage imageNamed:@"checkbox_unchecked.png"]];

    }    
    UIImageView *imageViews=(UIImageView *)[self.view viewWithTag:indexPath.row];
    [imageViews setImage:[UIImage imageNamed:@"checkbox_checked.png"]];
}

So on clicking any tableview cell the images gets sets. But once if I click on objectatindex:0 then the app crashes. I'm unable to fix this.

Below is the crash log:

2012-08-20 16:25:36.321 EventApp[2422:12503] -[UIView setImage:]: unrecognized selector sent to instance 0x79642b0
2012-08-20 16:25:36.321 EventApp[2422:12503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x79642b0'
*** First throw call stack:
(0x1de3022 0x1c03cd6 0x1de4cbd 0x1d49ed0 0x1d49cb2 0x7a98c 0xc615c5 0xc617fa 0x14f685d 0x1db7936 0x1db73d7 0x1d1a790 0x1d19d84 0x1d19c9b 0x1be57d8 0x1be588a 0xbd0626 0x380a2 0x23b5)
terminate called throwing an exception(lldb) 

Upvotes: 1

Views: 4103

Answers (2)

Pandey_Laxman
Pandey_Laxman

Reputation: 3908

I think you are not getting UIImageView Object,you are getting uiview types object that's why it crashes. you should try to Define another tag property like 999+indexPath.row. Got it somewhere you define the tag=0 or IB automatically takes tag=0 to all object so it taking uiview with tag 0 not uiimageView

Upvotes: 5

medvedNick
medvedNick

Reputation: 4510

this means that you are sending message -(void)setImage to UIView, not to UIImageView. Make sure that view with tag indexPath.row and all radioButtons in array are actually UIImageView

Upvotes: 0

Related Questions