这段代码应该显示一个带有文本输入的警报窗口:
self.alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[self.alert show];
导致此错误:
Thread 7: Program received signal: "EXC_BAD_ACCESS"
这是 self.alert 的定义方式:
@interface MyClass : NSObject
{
UIAlertView *alert;
id <MyClassDelegate> __unsafe_unretained delegate;
}
@property (nonatomic, retain) UIAlertView *alert;
@property (unsafe_unretained) id <MyClassDelegate> delegate;
最佳答案
问题可能是因为自定义。
我不知道为什么,但在我看来,问题是因为使用了线程+自定义了警报。
您可以尝试在主线程上显示此警报吗?会发生什么?
您可能会在这一行中遇到错误: self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
如果是,您需要做的是在主线程中执行此操作。
- (void) yourMethod{
[self performSelectorOnMainThread:@selector(yourMethod2) withObject:nil waitUntilDone:NO];
}
- (void) yourMethod2{
self.alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[self.alert show];
}
抱歉,无法为您提供更多帮助,但我不知道到底发生了什么,但我已经在其他线程中阅读了编辑要显示的内容时出现的问题。
希望对你有帮助!
关于iphone - 无法显示带有文本字段的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10037123/