Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在iPad上从UIBarbuttonite中删除UIActionSheet_Ios_Ipad_Uibarbuttonitem_Uiactionsheet - Fatal编程技术网

Ios 在iPad上从UIBarbuttonite中删除UIActionSheet

Ios 在iPad上从UIBarbuttonite中删除UIActionSheet,ios,ipad,uibarbuttonitem,uiactionsheet,Ios,Ipad,Uibarbuttonitem,Uiactionsheet,我有一个UIToolbar和几个UIBarButtonItems,它们使用showFromBarButtonItem:显示各种UIActionSheets 在iPad上,当其中一张动作表出现在屏幕上时,触摸动作表之外的任何地方都会将其移除,而不会执行其他操作(例如,触摸按钮不会触发按钮)。这是故意的——我不高兴,但我接受它,只要它是正常的行为 但有一个例外。如果我触摸另一个UIBarButtonItem,则会触发此按钮,并且当前操作表不会从屏幕上删除。如果新按钮碰巧启动另一个ui操作表,屏幕上就

我有一个
UIToolbar
和几个
UIBarButtonItem
s,它们使用
showFromBarButtonItem:
显示各种
UIActionSheet
s

在iPad上,当其中一张动作表出现在屏幕上时,触摸动作表之外的任何地方都会将其移除,而不会执行其他操作(例如,触摸按钮不会触发按钮)。这是故意的——我不高兴,但我接受它,只要它是正常的行为

但有一个例外。如果我触摸另一个
UIBarButtonItem
,则会触发此按钮,并且当前操作表不会从屏幕上删除。如果新按钮碰巧启动另一个
ui操作表
,屏幕上就会出现两个(或更多)操作表

当然,我可以经历一个繁琐的过程,记住屏幕上的内容并手动将其取消,但我也担心用户,因为一些触摸(针对工具栏按钮的触摸)会得到尊重,而其他触摸则会被忽略


在这种情况下,我能做些什么,或者必须做些什么?

这似乎是一个令人讨厌的矛盾,但不是一个很难纠正的矛盾。本例假设您只需要显示
UIActionSheets
,您似乎就是这样

下面是一个如何解决此问题的功能示例,从
.h
开始:

@interface TestToolBarExclusiveActionSheet : UIViewController <UIActionSheetDelegate>{
    UIActionSheet *sheetShowing;
}
@property (weak, nonatomic) IBOutlet UIBarButtonItem *oneButton;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *twoButton;
@end
最后是
.xib
的屏幕截图(以iPhone模式显示图像大小):

只需连接按钮插座,并将两个按钮动作连接到
targetforboth按钮:
方法


您将看到,如果显示其中一张操作表,则按下任何条形按钮都会导致操作表被取消。

谢谢。我担心这是唯一的选择,但我确实错过了cancelButtonIndex属性,它使事情变得更简单。
#import "TestToolBarExclusiveActionSheet.h"
@implementation TestToolBarExclusiveActionSheet
@synthesize oneButton;
@synthesize twoButton;
-(IBAction)targetForBothButtons:(UIBarButtonItem *)button{
    if (sheetShowing != nil){
        [sheetShowing dismissWithClickedButtonIndex:[sheetShowing cancelButtonIndex] animated:YES];
        sheetShowing = nil;
    }
    else{ // I am free to act on the button push.
        // Just for demo.. So:
        sheetShowing = [[UIActionSheet alloc] initWithTitle:button.title delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:nil, nil];
        [sheetShowing showFromBarButtonItem:button animated:YES];
    }
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    sheetShowing = nil;
    // Respond to action sheet like normal
}
-(void)viewDidUnload{
    [self setOneButton:nil];
    [self setTwoButton:nil];
    [super viewDidUnload];
}
@end