我创建一个类来调用UIAlertview在屏幕上显示。我在另一个类中编写UIAlert函数。 这两个类都不是我的viewController类。
我使用此UIAlert(内部是UITextfield)将文本存储到plist文件中。
这是调用UIAlert的类:
#import "Story.h"
@implementation Story
...
+ (void)stage1
{
AlertClass *pointer = [AlertClass new];
[pointer doAlert];
}
这是AlertClass.m类的文件:
- (void)doAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
//this makes crash!
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
self.storyFlow.text = [alertView textFieldAtIndex:0].text;
}
在.h中添加UIAlertViewDelegate并覆盖方法“clickedButtonAtIndex”之前,它很好用。但是,我需要在警报 View 中存储来自UITextfield的一些数据。我崩溃了,不知道它响应的消息如下。
请帮我解决这个问题。谢谢。
[崩溃图片] https://dl.dropbox.com/u/47381923/crash.tiff
最佳答案
对您从“警报” View 返回的文本执行NSLog,以查看是否是崩溃或随后的'self.storyFlow.text ='导致了崩溃。也许self.storyFlow尚未创建(使用alloc / init)
关于iphone - 通过添加clickedButtonAtIndex导致UIAlertView崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12435860/