UIActionSheet 在 iPad 上崩溃/而非 iPhone

发布于 2024-09-19 21:13:01 字数 1632 浏览 8 评论 0原文

当我查看控制台时,我收到此消息

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

千鲤 2024-09-26 21:13:01

错误消息显示:

无效参数不满足:view != nil

可能来自这一行:

[actionSheet showInView:self.view];

既然你说这适用于 iPhone 但不适用于 iPad,这意味着 iPad 到达此行的代码路径可能与 iPhone 到达此行的代码路径不同到达这条线。这意味着视图控制器的 view 属性可能未针对 iPad 设置。

我的猜测:您忘记在 Interface Builder 中为该视图控制器正在使用的 xib 的 iPad 版本连接 view 插座。

The error message says:

Invalid parameter not satisfying: view != nil

Likely from this line:

[actionSheet showInView:self.view];

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.

匿名。 2024-09-26 21:13:01

我也遇到了这个问题,但我正在使用 [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).

北斗星光 2024-09-26 21:13:01

这样做:

[self performSelectorOnMainThread:@selector(choosePhoto) withObject:nil waitUntilDone:NO];

-(void)choosePhoto
{

    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                  delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                         otherButtonTitles:@"Take Photo", @"Choose from gallery", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    actionSheet.tag = 1;
    [actionSheet showInView:self.view];
    [actionSheet release];
}

为我工作

do like this:

[self performSelectorOnMainThread:@selector(choosePhoto) withObject:nil waitUntilDone:NO];

-(void)choosePhoto
{

    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                  delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                         otherButtonTitles:@"Take Photo", @"Choose from gallery", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    actionSheet.tag = 1;
    [actionSheet showInView:self.view];
    [actionSheet release];
}

Worked for me

傲鸠 2024-09-26 21:13:01

我认为问题是视图还没有出现。将其放入 viewDidAppear: 中,它应该可以正常工作。

I believe the problem is that the view has not appeared yet. Put it in viewDidAppear: and it should work fine.

叹梦 2024-09-26 21:13:01

对于像我这样使用 UIActionSheet 的人可能与最初的问题略有不同,但在 iPad 上仍然失败,我一直在使用:

[actionSheet showFromRect:m_view.bounds inView:m_view animated:YES];
[actionSheet release];

...在 iPhone 上工作,但在 iPad 上失败。

此示例适用于我在两种设备上的特定应用程序:

[actionSheet showInView:m_view];
[actionSheet release];

问候,大卫

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:

[actionSheet showFromRect:m_view.bounds inView:m_view animated:YES];
[actionSheet release];

...which works on iPhone but fails on iPad.

This example works in my particular app on both devices:

[actionSheet showInView:m_view];
[actionSheet release];

Regards, David

冰魂雪魄 2024-09-26 21:13:01

这是一个老问题,但我今天遇到了同样的问题。
我有一个 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 the UIActionSheet was causing the iPad app to crash.

Turned out calling showInView in the viewDidAppear, instead of viewDidLoad 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_

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文