UIActionSheet,如何一键关闭它?
UIActionSheet,如何一键关闭它? 我必须单击一个按钮两次才能将其关闭,我该怎么做才能使其在第一次单击后可关闭?!这是我的代码:
-(void)buttonHeld:(id)sender
{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Delete Contact?!" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles: nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"Delete button clicked Button Clicked");
else if (buttonIndex == 1) {
NSLog(@"Cancel Button Clicked");
}
}
UIActionSheet, how to dismiss it with a single click?
I have to click a button 2 times so it gets dismissed, what should I do to make it dismissble after the first click?! Here is my code:
-(void)buttonHeld:(id)sender
{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Delete Contact?!" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles: nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"Delete button clicked Button Clicked");
else if (buttonIndex == 1) {
NSLog(@"Cancel Button Clicked");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据您的方法“buttonHeld”的名称,我的假设是您正在尝试从 UILongPressGestureRecognizer 启动 UIActionSheet。如果您希望它按预期工作,您将需要使用下面列出的代码。该问题源于 UILongPressGestureRecognizer 是一种“连续手势”,会多次触发并经历几种不同的状态。您需要监视正确的状态,然后加载 UIActionSheet。我遇到了完全相同的问题,这就是为我解决的问题。
Based on the name of your method "buttonHeld", my assumption is that you are trying to launch the UIActionSheet from a UILongPressGestureRecognizer. You will need to use the code listed below if you want it to work as expected. The problem stems from UILongPressGestureRecognizer being a 'continuous gesture' which fires multiple times and progresses through several different states. You'll need to monitor for the correct state and then load your UIActionSheet. I had the exact same problem and this is what solved it for me.
这就是我关闭操作表的方式...
希望这有帮助
This is how i dismiss the actionsheet...
Hope this helps
我也点击了几下才将其取消。问题最终是我将它附加到哪个视图。
self.view仅在IB中被引用。我将其更改为不同的视图并且有效。
It took me a few taps to get it to cancel as well. The problem ended up being which view I attached it to.
self.view was only referenced in IB. I changed it to a different view and it worked.
当您分配操作表时,无需在此委托中声明取消按钮,默认情况下会
从任何其他事件中关闭操作表,您可以使用此方法
在您的代码中存在语法错误,您将 else 块放入其中如果阻止。
No need to declare in this delegate when you alloc the actionsheet you have make cancel Button that by default dismiss the ActionSheet some thing like this
from any other event you can use this method
In your code there is a syntax error you are putting else block in if block.
如果您正在为 iPhone 进行开发,那么使用起来总是安全的:
或 showFromTabBar: 或 showFromToolBar 等而不是 showinView。
If u're developing for the iphone it's always safe to use :
or showFromTabBar: or showFromToolBar etc. instead of showinView.