gpt4 book ai didi

iphone - 按下 UIBarButton 时 UIAction 表不会消失

转载 作者:行者123 更新时间:2023-12-03 20:28:18 25 4
gpt4 key购买 nike

我正在从 UIBarButtonItem 呈现 UIActionSheet。当我再次单击栏按钮时,我希望操作表消失,而是每次都会创建一个新的操作表,彼此层叠。有什么想法吗?

- (IBAction)actionButtonClicked:(id)sender
{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Action Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Help", @"Lock", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showFromBarButtonItem:sender animated:YES];
[popupQuery release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[self erxButtonClicked];
}
else if (buttonIndex == 1)
{
[self erxRefillButtonClicked];
}
}

最佳答案

我会在我的类上为 popupQuery 声明一个 @property 并用它来跟踪操作表。

- (IBAction)actionButtonClicked:(id)sender
{
// If self.popupQuery is not nil, it means the sheet is on screen and should be dismissed. The property is then set to nil so a new sheet can be created next time.
if (self.popupQuery)
{
[self.popupQuery dismissWithClickedButtonIndex:self.popupQuery.cancelButtonIndex animated:YES];
self.popupQuery = nil;

return;
}

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Action Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Help", @"Lock", nil];
sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
sheet.delegate = self;
self.popupQuery = sheet;
[sheet release];

[self.popupQuery showFromBarButtonItem:sender animated:YES];
}

// Implementing this method to be notified of when an action sheet dismisses by means other than tapping the UIBarButtonItem. We set the property to nil to prepare for lazy instantiation next time.
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
self.popupQuery = nil;
}

关于iphone - 按下 UIBarButton 时 UIAction 表不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7761546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com