我有一个显示9个UIImageViews的应用程序,我正在尝试添加用户删除它们的功能。因此,我将其设置为全部,并为用户设置警报视图,以确认他们要删除他们所点击的图像。当我在警报视图中单击“是”时,应用程序崩溃,调试器指出:
2012-04-04 18:19:44.311 AppName [1857:f803] - [UIControl setImage:]:无法识别的选择器发送到实例0x6aac690
2012-04-04 18:19:44.312 AppName [1857:f803]由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIControl setImage:]:无法识别的选择器发送到实例0x6aac690'< /强>
奇怪的是我在任何代码中都没有调用setImage。这是我正在使用的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
if (imageView.image == nil) {
imageView.image = img;
self.array = [NSMutableArray arrayWithObject:[NSData dataWithData:UIImagePNGRepresentation(imageView.image)]];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
if (imageView2.image == nil) {
imageView2.image = img;
NSLog(@"The image is a %@", imageView);
[self.array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView2.image)]];
[picker dismissModalViewControllerAnimated:YES];
[self.popover dismissPopoverAnimated:YES];
return;
}
}
.....
- (IBAction)deleteButtonPressed:(id)sender {
NSLog(@"Sender is %@", sender);
UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:@"Delete"
message:@"Are you sure you want to delete this photo?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
[deleteAlertView show];
int imageIndex = ((UIButton *)sender).tag;
deleteAlertView.tag = imageIndex;
}
- (void)alertView: (UIAlertView *) alertView
clickedButtonAtIndex: (NSInteger) buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(@"User Clicked Yes. Deleting index %d of %d", alertView.tag, [array count]);
NSLog(@"The tag is %i", alertView.tag);
[self.array removeObjectAtIndex: alertView.tag];
NSLog(@"After deleting item, array count = %d", [array count]);
NSLog(@"Returned view is :%@, in view: %@", [self.view viewWithTag:alertView.tag], self.view);
((UIImageView *)[self.view viewWithTag:alertView.tag]).image =nil;
}
[self.user setObject:self.array forKey:@"images"];
}
我添加了断点,导致崩溃的行似乎是:
((UIImageView *)[self.view viewWithTag:alertView.tag]).image =nil;
该行的目的是从UI中删除图像。我不确定为什么该行导致此错误,但代码似乎是正确的。有问题的nib文件是一个UIControl,而不仅仅是一个UIView,所以这可能是问题所在。非常感谢任何帮助或建议,谢谢!
答案 0 :(得分:0)
事实证明我的标签搞砸了。我在UIImageView上标记了隐形按钮,忘记它不是真正的UIImageView。这解释了所有的怪异。我这次按照UIButtons标记了实际的UIImageViews,现在工作正常。感谢大家的帮助。
答案 1 :(得分:-1)
UIControl没有图像属性。您错误地将imageView视为UIControl