ios - ARC 和 UIAlertView : unrecognized selector sent to instance

标签 ios uialertview automatic-ref-counting

这是我如何显示 UIAlertView 和委托(delegate) clickedButtonAtIndex -

UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle: @"title"
                               message: @"message"
                              delegate: self
                     cancelButtonTitle: @"Cancel"
                     otherButtonTitles: @"Continue", nil];

    [alert show];


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //something
}

这段代码在没有 ARC 的情况下也能完美运行。但是对于 ARC 它会抛出这个错误 - 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFType alertView:clickedButtonAtIndex:]: 无法识别的选择器发送到实例 0x859d790”

关于委托(delegate)为何抛出此错误的任何想法?

最佳答案

您的委托(delegate)已被解除分配。仔细检查您的代码以确保显示警报并将自身设置为委托(delegate)的对象以某种方式被保留(即:您应用中的某些内容对它有很强的引用)。

关于ios - ARC 和 UIAlertView : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514548/

相关文章:

ios - 导致错误的 UIAlertView 按钮操作

IOS ARC NSMutableArray 我需要在为其分配新内存之前删除所有对象吗

ios - Cocoapods:如何启用 OS_OBJECT_USE_OBJC? (GCD 队列作为适当的 ObjC 对象)

ios - 基础类(class)的扩展

iOS JPEG 优化

ios - 使用 NSURLConnection 获取 302 HTTP 重定向的响应主体

ios - 水平方向 UICollectionView 与 UIRefreshControl reloadData() 不工作

ios - 为 UIAlertAction 编写处理程序

ios - 如何使用两个#imports?

objective-c - 使用 ARC 返回自动释放的 CFTypeRef