0

我有一个显示 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,所以这可能是问题所在。非常感谢任何帮助或建议,谢谢!

4

2 回答 2

0

原来我的标签搞砸了。我在 UIImageView 上标记了不可见的按钮,忘记了它不是实际的 UIImageView。这解释了所有的奇怪之处。这次我根据 UIButtons 标记了实际的 UIImageViews,它现在可以正常工作了。感谢大家的帮助。

于 2012-04-05T01:51:05.793 回答
-1

UIControl 没有图像属性。您将 imageView 误认为是 UIControl

于 2012-04-05T00:30:42.433 回答