iPad 上的操作表不显示“取消”按钮

发布于 2024-08-30 20:16:15 字数 559 浏览 6 评论 0原文

在 iPhone 上,此代码显示取消按钮:

- (IBAction)buttonPressed
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"Are you sure?"
                                  delegate:self 
                                  cancelButtonTitle:@"No way!"
                                  destructiveButtonTitle:@"Yes, I'm sure!"
                                  otherButtonTitles:nil];
    [actionSheet showInView:self.view];
    [actionSheet release];  
}

但在 iPad 上,仅显示破坏性按钮。
有什么问题吗?

On the iphone, this code shows the cancel button:

- (IBAction)buttonPressed
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"Are you sure?"
                                  delegate:self 
                                  cancelButtonTitle:@"No way!"
                                  destructiveButtonTitle:@"Yes, I'm sure!"
                                  otherButtonTitles:nil];
    [actionSheet showInView:self.view];
    [actionSheet release];  
}

But on the iPad, only the destructive button shows.
What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

我偏爱纯白色 2024-09-06 20:16:15

这是UI 设计和指南。在“行动表”下,他们说:

不包含“取消”按钮,
因为人们可以点击外部
弹出窗口以关闭操作表
而不选择其中之一
替代方案。

看起来SDK 故意为您隐藏了按钮。我不确定是否有解决方案,但也许您可以添加自己的按钮并设置 cancelButtonIndex 进行匹配。或者您可以切换到 UIAlertView。

This is part of the UI design and guidlines. Under 'Action Sheet' they say:

Do not include a Cancel button,
because people can tap outside the
popover to dismiss the action sheet
without selecting one of the other
alternatives.

It looks like the SDK hide the button for you on purpose. I'm not sure there is a solution, but maybe you could add your own button and set the cancelButtonIndex to match. Or you could switch to UIAlertView.

旧人哭 2024-09-06 20:16:15

在 iOS 5 中,这对我有用。

- (void)manualAddModel
{
    UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle: @"Select Equipment Type"
                                                            delegate: self
                                                   cancelButtonTitle: @"Cancel"
                                              destructiveButtonTitle: nil
                                                   otherButtonTitles: @"Add Boiler", @"Add Furnace",  nil];

    popupQuery.actionSheetStyle = UIActionSheetStyleDefault;
    [popupQuery addButtonWithTitle:@"Cancel"];
    [popupQuery showInView:self.view];
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        NSLog(@"Add Boiler");
    }
    else if (buttonIndex == 1)
    {
        NSLog(@"Add Furnace");
    }
    else if (buttonIndex == 2)
    {
        NSLog(@"Cancel Button Clicked");
    }
}

通常,在 iPad 中点击操作表外部也能达到相同的目的。

In iOS 5, this worked for me.

- (void)manualAddModel
{
    UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle: @"Select Equipment Type"
                                                            delegate: self
                                                   cancelButtonTitle: @"Cancel"
                                              destructiveButtonTitle: nil
                                                   otherButtonTitles: @"Add Boiler", @"Add Furnace",  nil];

    popupQuery.actionSheetStyle = UIActionSheetStyleDefault;
    [popupQuery addButtonWithTitle:@"Cancel"];
    [popupQuery showInView:self.view];
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        NSLog(@"Add Boiler");
    }
    else if (buttonIndex == 1)
    {
        NSLog(@"Add Furnace");
    }
    else if (buttonIndex == 2)
    {
        NSLog(@"Cancel Button Clicked");
    }
}

Normally, tapping outside the actionsheet will serve the same purpose in iPad.

梦晓ヶ微光ヅ倾城 2024-09-06 20:16:15

看起来在 iOS 4.2.1 中,您可以像普通按钮一样手动添加自己的取消按钮:

[actionSheet addButtonWithTitle:@"Cancel"];

然后设置:

actionSheet.cancelButtonIndex = <your index>;

您不会获得红色取消按钮,但根据您的您将获得蓝色或黑色按钮>UIActionSheetStyle 设置。无论如何,它与普通按钮非常明显区分,并且可以正确取消。

请注意,在我的例子中,我显示的是弹出窗口控制器内的操作表,您的结果在其他情况下可能会有所不同。

It looks like in iOS 4.2.1 you can manually add your own Cancel button like a normal button:

[actionSheet addButtonWithTitle:@"Cancel"];

And then set:

actionSheet.cancelButtonIndex = <your index>;

You won't get the red cancel button, but you will get either a blue or black one depending on your UIActionSheetStyle setting. In any event, it is pretty clearly distinguishable from the normal buttons and does correctly cancel.

Note that in my case I am showing an action sheet from within a popover controller, your results may vary in other scenarios.

情场扛把子 2024-09-06 20:16:15

我能够通过设置 actionSheetStyle 来解决这个问题:

actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

UIActionSheetStyleBlackTranslucent 也可以。我正在从模态视图控制器显示操作表,我猜它在技术上不是像指南所说的“弹出控制器”,但在操作表上看不到“取消”按钮,当它出现在模态视图顶部时看起来不正确。用户看到的只是一个可怕的红色按钮,没有可见的替代按钮。

也许我可以将模式视图控制器更改为弹出控制器,但这样它就不会是它需要的模式。

--更新--

嗯,虽然它持续很有趣,但在 iOS 4.2 中不再有效。
我改用 UIAlertView 而不是 UIActionSheet。
我不再有一个很酷的红色按钮,但它可以完成工作。

I was able to solve this by setting the actionSheetStyle:

actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

UIActionSheetStyleBlackTranslucent also works. I am displaying the action sheet from a modal view controller which I guess is not technically a "popovercontroller" like the guidelines say but not seeing a Cancel button on the action sheet doesn't look right when it appears on top of the modal view. All the user sees is one scary red button with no visible alternative.

Maybe I could change the modal view controller to a popovercontroller but then it wouldn't be modal which it needs to be.

--Update--

Well it was fun while it lasted but this no longer works in iOS 4.2.
I switched to using a UIAlertView instead of a UIActionSheet.
I no longer get a cool red button but it gets the job done.

浅忆流年 2024-09-06 20:16:15

当我尝试在另一个模式视图下的视图中显示 ActionSheet 时,我遇到了同样的问题,例如视图不可见。尽管 View 看起来不是 nil ,但它在框架中看起来并不为零,但当它没有显示时就意味着如此。

我通过设置不同的 UIModalPresentationStyle modalPresentationStyle 属性解决了该问题,以便视图变得可见。

view.modalPresentationStyle = UIModalPresentationFormSheet;

I had the same issue when I tried to show ActionSheet in the View that was under another modal view, e.g. the view was invisible. Though the View wasn't nil looks like deep in framework it means so when it's not shown.

I solved the problem by setting a different UIModalPresentationStyle modalPresentationStyle property so the view became visible.

view.modalPresentationStyle = UIModalPresentationFormSheet;
西瓜 2024-09-06 20:16:15

根据 iOS 标准,在 iPad 中显示时,UIActionSheet 中不会显示取消按钮,因为只需点击 ActionSheet 区域之外的任何位置即可取消(隐藏)UIActionSheet。如果是 iPhone,UIActionSheet 将包含“取消”按钮。

请参阅此链接了解更多信息 iPad 中的 UIActionSheet 取消按钮< /a>

According to iOS standard Cancel button is not displayed in UIActionSheet when displayed in iPad since UIActionSheet can be cancelled (Hide) by simply tapping any where outside ActionSheet region. In case of iPhone UIActionSheet will contain Cancel button.

Refer this link for further information UIActionSheet Cancel button in iPad

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