UIAlertView崩溃通过添加clickedButtonAtIndex

问题描述:

我创建一个类来调用UIAlertview显示在我的屏幕上。我在另一个类中编写UIAlert函数。 这两个类都不是我的viewController类UIAlertView崩溃通过添加clickedButtonAtIndex

我使用这个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” ,它的效果很好。但是,我需要在警报视图内存储来自UITextfield的一些数据。我崩溃了,不知道它响应的消息如下。

请帮我解决这个问题。谢谢。

[崩溃图] https://dl.dropbox.com/u/47381923/crash.tiff

+0

提供图像不是最好的解决方案...至少如果它是一个JPEG或PNG ......但它是一个TIFF!好吧,无论如何...而不是原始汇编,如果你复制了你得到的堆栈跟踪会更好。 – 2012-09-15 09:01:45

+0

您是否检查过alertview中的文本是否有效,同时您的self.storyFlow被初始化并且不为空? –

做一个NSLog的你得到警报视图背课文,看看这是否是在崩溃或“self.storyFlow.text =”导致它的后续。也许self.storyFlow尚未创建(使用alloc/init)

+0

我做了一个NSLog,它没有回应。即使我留下空的“clickedButtonAtIndex”它仍然崩溃.. – Graphite

+1

如果你的AlertClass继承自NSObject,它不能处理委托alertView'clickedAtButtonAtIndex'方法;你需要把它放在视图控制器中,以便它最终从UIView – SPA

+0

继承。最后,我发现问题是..谢谢〜 – Graphite