简体   繁体   English

iOS 7.1 应用程序在显示警报视图时崩溃

[英]iOS 7.1 app is crashing in showing alert view

I have used alertview many times but currently i have an issue.我已经多次使用alertview,但目前我有一个问题。 My app is working in all the version except it is crashing in iOS 7.1.我的应用程序在所有版本中都可以运行,除了在 iOS 7.1 中崩溃。 Below is the log message.下面是日志消息。

[_UIBarBackgroundCustomImageContainer image]: message sent to deallocated instance 0x13b88840

 UIAlertView *alert  =   [[UIAlertView alloc]initWithTitle:@"Title" @"Test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
 [alert show];

I don't understand why it is only crashing in iOS 7.1我不明白为什么它只在 iOS 7.1 中崩溃

Are you sure to be on main thread ?你确定在主线程上吗?

You can test it like this : [NSThread isMainThread];你可以这样测试: [NSThread isMainThread];

As requested by the OP I have just moved my comments to be an answer.按照 OP 的要求,我刚刚将我的评论移到了答案中。

There are a few issues wrong with the following line:以下行有几个问题:

[[UIAlertView alloc]initWithTitle:@"TestTitle" @"Test" delegate:self cancelButtonTitle:kActionOk otherButtonTitles:nil, nil];

just replace it with只需将其替换为

[[UIAlertView alloc]initWithTitle:@"TestTitle" message:@"Test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

As for what the issues are with that line, they are:至于那条线的问题是什么,它们是:

1) The method initWithTitle:delegate:cancelButtonTitle:otherButtonTitles: isn't a real instance method for UIAlertView so it shouldn't work in any iOS where as you have said it does work in iOS versions prior to 7. The method that you should be using is initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: notice the extra parameter message: this is the main issue and should create a compiler error and if it got passed that should throw a runtime error of unrecognised selector . 1) 方法initWithTitle:delegate:cancelButtonTitle:otherButtonTitles:不是UIAlertView的真正实例方法,所以它不应该在任何iOS中工作,正如你所说的它在 7 之前的iOS版本中工作。你应该使用的方法正在使用的是initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:注意额外的参数message:这是主要问题,应该创建一个编译器错误,如果它通过,应该抛出unrecognised selector的运行时错误。

2) The second is is that you have two nil s being passed in for the last parameter for otherButtonTitle: , this parameter is nil terminated so as soon as it sees nil it will end what can be passed into that parameter so the second nil is pointless and never seen. 2)第二个是你有两个nil被传递给otherButtonTitle:的最后一个参数,这个参数被nil终止,所以一旦它看到nil它将结束可以传递给该参数的内容,所以第二个nil是毫无意义,从未见过。 This also may create a compiler error but would be in the shadows of the first issue (1)这也可能会导致编译器错误,但会处于第一个问题 (1) 的阴影中

For more information in regards to UIAlertView please the Apple Documentation on UIAlertView对于关于更多信息UIAlertView取悦苹果文档UIAlertView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM