2012-09-25 55 views
1

每当我的应用程序打开,如果检查某些条件。如果失败,则向用户显示UIAlertView。xcode 4.4.1 uialertview崩溃

构建在xcode 4.4.1崩溃时执行,当[alertview show]执行时,它在xcode 4.3.2和xcode 4.5中正常工作。

这里是错过了一个重要信息的代码

NSString *appMessage = [NSString stringWithFormat:@"Error Message HERE"]; 
UIAlertView *appMessageAlertView = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(appMessage,@"Error Message") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", @"ok"),nil]; 
appMessageAlertView.delegate = self; 
[appMessageAlertView show]; 
[appMessageAlertView release]; 

:坠机发生在iOS6的

回答

0

显示或dissmissed时UIAlertView中的delgates方法被调用。所以加

<UIAlertViewDelegate> in .h 

再进一步崩溃

delegate:nil in line 2 

然后删除

appMessageAlertView.delegate = self; 

[appMessageAlertView release]; 
+0

在除去释放 - 不使分配/初始化不平衡?使用ARC时不允许使用 – Farcaller

+0

版本,但这会给你一个编译错误。当不使用ARC时,版本应该在那里。 – pre

+0

崩溃!=编译错误。我假设,如果有一个ARC问题,它也会在xcode 4.5中引人注目。 – Farcaller

0

尝试设置标题字符串。

而且你的第一线可以简化为: NSString *appMessage = @"Error Message HERE";

3号线也没有必要的,因为你已经设置委托在2

线如果已经启用了ARC [appMessageAlertView release];是不允许的。

您有使用otherButtonTitles的原因吗?为什么不简单设置cancelButtonTitleNSLocalizedString(@"OK", nil)

0

试试这个,它会工作:

UIAlertView *appMessageAlertView = [[UIAlertView alloc] initWithTitle:nil message:@"Error Message" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok",nil]; 
[appMessageAlertView show]; 
[appMessageAlertView release];