2

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

2010-09-18 17:04:05.284 浪费时间[8998:207] *** -[UIActionSheet showInView:] 中的断言失败,/SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073
2010-09-18 17:04:05.286 浪费时间 [8998:207] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效参数不满足:视图!= nil”
2010-09-18 17:04:05.286 浪费时间[8998:207] 堆栈:(
    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
)
在抛出“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 模拟器中崩溃。

4

6 回答 6

5

错误消息说:

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

可能来自这一行:

[actionSheet showInView:self.view];

由于您说这适用于 iPhone 但不适用于 iPad,这意味着 iPad 到达该行所采用的代码路径可能与 iPhone 到达该行所采用的代码路径不同。这意味着view可能没有为 iPad 设置视图控制器的属性。

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

于 2010-09-18T21:14:30.627 回答
3

我也遇到了这个问题,但我正在使用 [actionSheet showInView:[self.view window]]; (修复另一个错误,其中只有一半的取消按钮是可选的)。

现在我有条件地将其更改为[actionSheet showInView:self.view];在 iPad 上。

我发现最好不要在 iPad 上将样式设置为 UIActionSheetStyleBlackTranslucent —— iPad 有它自己的样式,设置它似乎添加了取消按钮(默认情况下在 iPad 上不显示)。

于 2010-11-10T11:37:45.210 回答
0

这样做:

[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];
}

为我工作

于 2010-09-27T14:29:22.037 回答
0

我相信问题是视图还没有出现。把它放在 viewDidAppear: 中,它应该可以正常工作。

于 2012-01-27T00:03:48.423 回答
0

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

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

...适用于 iPhone 但在 iPad 上失败。

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

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

问候,大卫

于 2012-08-30T16:48:57.610 回答
0

这是一个老问题,但我今天遇到了同样的问题。我有一个用于 iPhone 和 iPad 通用的 UIViewController 的 xib 文件,并且该showInView方法UIActionSheet导致 iPad 应用程序崩溃。

结果是打电话showInView给我viewDidAppear,而不是viewDidLoad为我修好。在 iPad 上调用 viewDidLoad 时,可能所有 IB 连接都没有建立。

(我的 UIViewController 被推到 UINavigationController 上,所以我想知道增加的动画时间是否是导致整个问题的原因_

于 2013-08-06T21:05:09.793 回答