iPad 上的操作表不显示“取消”按钮
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是UI 设计和指南。在“行动表”下,他们说:
看起来SDK 故意为您隐藏了按钮。我不确定是否有解决方案,但也许您可以添加自己的按钮并设置
cancelButtonIndex
进行匹配。或者您可以切换到 UIAlertView。This is part of the UI design and guidlines. Under 'Action Sheet' they say:
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 toUIAlertView
.在 iOS 5 中,这对我有用。
通常,在 iPad 中点击操作表外部也能达到相同的目的。
In iOS 5, this worked for me.
Normally, tapping outside the actionsheet will serve the same purpose in iPad.
看起来在 iOS 4.2.1 中,您可以像普通按钮一样手动添加自己的取消按钮:
然后设置:
您不会获得红色取消按钮,但根据您的
您将获得蓝色或黑色按钮>UIActionSheetStyle
设置。无论如何,它与普通按钮非常明显区分,并且可以正确取消。请注意,在我的例子中,我显示的是弹出窗口控制器内的操作表,您的结果在其他情况下可能会有所不同。
It looks like in iOS 4.2.1 you can manually add your own Cancel button like a normal button:
And then set:
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.
我能够通过设置 actionSheetStyle 来解决这个问题:
UIActionSheetStyleBlackTranslucent 也可以。我正在从模态视图控制器显示操作表,我猜它在技术上不是像指南所说的“弹出控制器”,但在操作表上看不到“取消”按钮,当它出现在模态视图顶部时看起来不正确。用户看到的只是一个可怕的红色按钮,没有可见的替代按钮。
也许我可以将模式视图控制器更改为弹出控制器,但这样它就不会是它需要的模式。
--更新--
嗯,虽然它持续很有趣,但在 iOS 4.2 中不再有效。
我改用 UIAlertView 而不是 UIActionSheet。
我不再有一个很酷的红色按钮,但它可以完成工作。
I was able to solve this by setting the actionSheetStyle:
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.
当我尝试在另一个模式视图下的视图中显示 ActionSheet 时,我遇到了同样的问题,例如视图不可见。尽管 View 看起来不是 nil ,但它在框架中看起来并不为零,但当它没有显示时就意味着如此。
我通过设置不同的 UIModalPresentationStyle modalPresentationStyle 属性解决了该问题,以便视图变得可见。
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.根据 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