iPad的UIActionSheet多次展示 [英] iPad's UIActionSheet showing multiple times
问题描述
我有一个名为-showMoreTools的方法:它是:
I have a method called -showMoreTools: which is:
- (IBAction) showMoreTools:(id)sender {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Close" otherButtonTitles:@"Add Bookmark", @"Add to Home Screen", @"Print", @"Share", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleDefault;
popupQuery.dismiss
[popupQuery showFromBarButtonItem:moreTools animated:YES];
[popupQuery release];
}
当用户点击 UIBarButtonItem
时,它会显示 UIActionSheet
,但是,如果用户想关闭 UIActionSheet
而不点击关闭按钮,(点击 UIBarButtonItem
,然后在第一个 UIActionSheet
上显示 UIActionSheet
。
When an user taps a UIBarButtonItem
it displays that UIActionSheet
, but then, if the user wants to close the UIActionSheet
without taping the Close button, (taping the UIBarButtonItem
, then it displays the UIActionSheet
over the first UIActionSheet
.
有可能以某种方式实现再次使用 UIBarButtonItem
来关闭 UIActionSheet
?
It's possible to implement somehow taping another time the UIBarButtonItem
to close the UIActionSheet
?
非常感谢你 - 我是iOS编程的新手!
Thank you so much – I'm a newbie in iOS Programming!
推荐答案
为了在您点击按钮两次时将其关闭,您需要跟踪当前显示的ActionSheet。我们在iPad应用程序中执行此操作并且效果很好。
In order to dismiss it when you click on the button twice, you need to keep track of the currently displaying ActionSheet. We do this in our iPad app and it works great.
在你的具有showMoreTools的类中,在标题中放置:
In your class that has the showMoreTools, in the header put:
@interface YourClassHere : NSObject <UIActionSheetDelegate> {
UIActionSheet* actionSheet_; // add this line
}
在类文件中,将其更改为:
In the class file, change it to:
-(IBAction) showMoreTools:(id)sender {
// currently displaying actionsheet?
if (actionSheet_) {
[actionSheet_ dismissWithClickedButtonIndex:-1 animated:YES];
actionSheet_ = nil;
return;
}
actionSheet_ = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Close" otherButtonTitles:@"Add Bookmark", @"Add to Home Screen", @"Print", @"Share", nil];
actionSheet_.actionSheetStyle = UIActionSheetStyleDefault;
[popupQuery showFromBarButtonItem:moreTools animated:YES];
[actionSheet_ release]; // yes, release it. we don't retain it and don't need to
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
// just set to nil
actionSheet_ = nil;
}
这篇关于iPad的UIActionSheet多次展示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!