简体   繁体   English

UIImageview设置图像崩溃

[英]UIImageview set image crash

I'm setting image to a UIImageView using in the below code 我在下面的代码中使用将图像设置为UIImageView

- (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. 因此,在单击任何tableview单元格时,图像将被设置。 But once if I click on objectatindex:0 then the app crashes. 但是一旦我单击objectatindex:0 ,应用程序就会崩溃。 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) 

I think you are not getting UIImageView Object,you are getting uiview types object that's why it crashes. 我认为您没有获取UIImageView对象,您正在获取uiview类型对象,这就是它崩溃的原因。 you should try to Define another tag property like 999+indexPath.row. 您应该尝试定义另一个标记属性,例如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 在定义标签= 0的某个地方找到它,否则IB会自动将标签= 0应用于所有对象,因此它将标签为0的uiview而不是uiimageView

this means that you are sending message -(void)setImage to UIView, not to UIImageView. 这意味着您正在将-(void)setImage消息发送到UIView,而不是UIImageView。 Make sure that view with tag indexPath.row and all radioButtons in array are actually UIImageView 确保带有标签indexPath.row的视图和数组中的所有radioButtons实际上都是UIImageView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM