0

xcode和objective-c的新手。所以请原谅我的菜鸟错误,但我已经有这个错误“'NSInvalidArgumentException',原因:'-[UIView isAnimating]: unrecognized selector sent to instance”已经有一天多了,并且已经做了很多搜索但没有成功。清理/构建应用程序时没有错误,但是当我单击按钮加载“UIIMagePickerController”时,应用程序终止并引发错误。请帮忙。谢谢

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
    if (self.imageView.isAnimating)
    {
        [self.imageView stopAnimating];
    }

    if (self.capturedImages.count > 0)
    {
        [self.capturedImages removeAllObjects];
    }

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    imagePickerController.sourceType = sourceType;
    imagePickerController.delegate = self;

    if (sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        imagePickerController.showsCameraControls = NO;

        [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
        self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
        imagePickerController.cameraOverlayView = self.overlayView;
        self.overlayView = nil;
    }

    self.imagePickerController = imagePickerController;
   [self presentViewController:self.imagePickerController animated:YES completion:nil];

}

4

3 回答 3

1

编译器正在将您的代码self.imageView.isAnimating变成[类似于]:

[[self imageView] isAnimating]

根据错误信息,[self imageView]正在返回一个UIView对象。isAnimating类上没有方法UIView,所以你得到一个异常。

找出在哪里[self imageView]设置,也许它在那里做错了什么?另外,您是否打开了ARC?这可能是内存管理错误。

于 2013-08-25T22:48:15.910 回答
0

尝试更改您的线路:

if (self.imageView.isAnimating)

if ([self.imageView isAnimating])

并确保self.imageView确实是并且UIImageView

于 2013-08-25T22:48:55.057 回答
0

该错误消息意味着您正在尝试向未实现它的对象发送消息(大致相当于在 Java、C++ 或大多数其他语言中调用函数)。这使得 Objective C 与许多其他流行语言不同。我建议阅读这篇文章,特别是说

系统在运行时确定程序正在执行时,给定对象是否响应特定消息,如果响应,则执行哪个方法。

此外,正如其他人指出的那样,错误消息表明您的imageView对象是 aUIView而不是 a UIImageView。弄清楚为什么会这样应该可以解决您的直接问题。

于 2013-08-25T22:49:48.010 回答