UIActionSheet 在 iPad 上崩溃/而非 iPhone
当我查看控制台时,我收到此消息
2010-09-18 17:04:05.284 Wasted Time[8998:207] *** Assertion failure in -[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073 2010-09-18 17:04:05.286 Wasted Time[8998:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil' 2010-09-18 17:04:05.286 Wasted Time[8998:207] Stack: ( 42272848, 43430700, 42010379, 811796, 3796273, 3862560, 9631, 3616645, 3688229, 3682846, 3690662, 3686119, 4983946, 71264534, 71263781, 71207378, 71206706, 3003734, 3030334, 3011831, 3043800, 51265916, 41552028, 41547944, 3002913, 3036018, 8314 ) terminate called after throwing an instance of 'NSException'
代码如下:
- (void)viewDidLoad {
BOOL continueYesNo;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
continueYesNo = [prefs boolForKey:@"keyContinueMeeting"];
if (continueYesNo) {
NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior Meeting"];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:message_continue
delegate:self
cancelButtonTitle:@"Reset"
destructiveButtonTitle:@"Continue"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
[message_continue release];
}
}
它在 iPhone 和 iPhone 模拟器中都运行良好,但在 iPad 模拟器中崩溃。
When I look in the console I get this message
2010-09-18 17:04:05.284 Wasted Time[8998:207] *** Assertion failure in -[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073 2010-09-18 17:04:05.286 Wasted Time[8998:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil' 2010-09-18 17:04:05.286 Wasted Time[8998:207] Stack: ( 42272848, 43430700, 42010379, 811796, 3796273, 3862560, 9631, 3616645, 3688229, 3682846, 3690662, 3686119, 4983946, 71264534, 71263781, 71207378, 71206706, 3003734, 3030334, 3011831, 3043800, 51265916, 41552028, 41547944, 3002913, 3036018, 8314 ) terminate called after throwing an instance of 'NSException'
The code is as follows:
- (void)viewDidLoad {
BOOL continueYesNo;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
continueYesNo = [prefs boolForKey:@"keyContinueMeeting"];
if (continueYesNo) {
NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior Meeting"];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:message_continue
delegate:self
cancelButtonTitle:@"Reset"
destructiveButtonTitle:@"Continue"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
[message_continue release];
}
}
It runs fine both in the iPhone and in the iPhone simulator, but crashes in the iPad simulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
错误消息显示:
可能来自这一行:
既然你说这适用于 iPhone 但不适用于 iPad,这意味着 iPad 到达此行的代码路径可能与 iPhone 到达此行的代码路径不同到达这条线。这意味着视图控制器的
view
属性可能未针对 iPad 设置。我的猜测:您忘记在 Interface Builder 中为该视图控制器正在使用的 xib 的 iPad 版本连接
view
插座。The error message says:
Likely from this line:
Since you say this works on iPhone but not iPad, that means that the code path the iPad takes to get to this line is probably different than the code path the iPhone takes to get to this line. Which means that the view controller's
view
property is probably not set for the iPad.My guess: you forgot to hook up the
view
outlet in Interface Builder for the iPad version of the xib this view controller is using.我也遇到了这个问题,但我正在使用
[actionSheet showInView:[self.view window]];
(修复另一个错误,其中只有一半的取消按钮可选)。现在,我在 iPad 上有条件地将其更改为
[actionSheet showInView:self.view];
。我发现最好不要在 iPad 上将样式设置为 UIActionSheetStyleBlackTranslucent – iPad 有自己的样式,并且设置此按钮似乎会添加取消按钮(默认情况下,iPad 上不会显示该按钮)。
I also had this problem but I was using
[actionSheet showInView:[self.view window]];
(to fix another bug where only half the cancel button is selectable).Now I conditionally change this to
[actionSheet showInView:self.view];
on the iPad.I found it's best not to the style to UIActionSheetStyleBlackTranslucent on the iPad either – the iPad has it's own style, and setting this seems to add the cancel button (which by default on the iPad is not shown).
这样做:
为我工作
do like this:
Worked for me
我认为问题是视图还没有出现。将其放入 viewDidAppear: 中,它应该可以正常工作。
I believe the problem is that the view has not appeared yet. Put it in viewDidAppear: and it should work fine.
对于像我这样使用 UIActionSheet 的人可能与最初的问题略有不同,但在 iPad 上仍然失败,我一直在使用:
...在 iPhone 上工作,但在 iPad 上失败。
此示例适用于我在两种设备上的特定应用程序:
问候,大卫
For those like me that may be using UIActionSheet slightly differently than in the original question, but still failing on iPad, I had been using:
...which works on iPhone but fails on iPad.
This example works in my particular app on both devices:
Regards, David
这是一个老问题,但我今天遇到了同样的问题。
我有一个 iPhone 和 iPad 通用的 UIViewController 的 xib 文件,
UIActionSheet
上的showInView
方法导致 iPad 应用程序崩溃。结果在
viewDidAppear
中调用showInView
,而不是viewDidLoad
为我修复了它。也许在 iPad 上调用 viewDidLoad 时,所有 IB 连接都尚未建立。(我的 UIViewController 被推送到 UINavigationController 上,所以我想知道动画时间的增加是否是导致整个问题的原因_
This is an old question, but I encountered the same problem today.
I have a xib file for a UIViewController that's common to iPhone and iPad, and the
showInView
method on theUIActionSheet
was causing the iPad app to crash.Turned out calling
showInView
in theviewDidAppear
, instead ofviewDidLoad
fixed it for me. Perhaps all IB connections weren't made by the time viewDidLoad was called on iPad.(my UIViewController was being pushed onto a UINavigationController, so I wonder if the increased animation time is what caused the whole issue_