【发布时间】:2012-09-19 23:51:49
【问题描述】:
我是 iphone 开发的新手,为了感受一下,我创建了一个新视图,每次加载时都会弹出一个警报。
这可以正常工作,但是当我关闭应用程序然后重新打开它时,整个应用程序崩溃。我唯一要做的就是显示警报。
这是我的警报代码:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"This is really annoying just to make"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
我想我应该输入 [alert release];,但 Xcode 一直说 release 不可用。
[alert release] 是我的应用在退出/重启时不断崩溃的原因吗?
谢谢!
编辑:这里是我调用 UIAlertView 的周围代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//just testing alerts..this shows up after the first load only
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"This is really annoying just to make"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
【问题讨论】:
-
ARC 不需要
release。如果您的项目刚刚开始(不超过几周),ARC 可能默认启用。崩溃肯定有其他原因。你在崩溃时遇到什么错误?另外,请尝试删除所有警报视图代码,看看是否是导致它的原因(我对此表示怀疑)。 -
你在哪里调用
[alert show]方法?它可能(但我怀疑)是线程问题 -
我在
(void) viewDidLoad方法中调用[alert show]。而且我没有收到错误;当我检查调试会话时,它说THREAD 1: SIGKILL所以我有点困惑 -
您需要显示新视图的代码 - 您发布的代码中没有任何内容会导致崩溃。
标签: objective-c ios