iphone - 通过添加clickedButtonAtIndex导致UIAlertView崩溃

标签 iphone crash uitextfield uialertview

我创建一个类来调用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/

相关文章:

xcode - 如何设置等于UITextField的字符串值?

ios - 如何在 Objective-C 中将完成处理程序分配给另一个完成处理程序

java - Android Studio 崩溃应用

iOS 在 MFMailComposeViewController 和 SKStoreProductViewController 的 init 方法上崩溃

Mysql 在条件插入时崩溃

ios - 从 TextFieldOnEditingDidEnd 内部调用 BecomeFirstResponder 时,iOS 6.1 中的 StackOverflow

ios - IQKeyboardManager 在 subview 中不工作

javascript - 在 SenchaTouch 中为 Ext.data.Store 代理设置请求 header

iphone - iOS:调整大小/裁剪录制的视频

iphone - 比较 NSNumber 和 NSInteger