Jon*_*Jon 2 iphone cocoa-touch objective-c uiactionsheet
我将从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];
}
}
Run Code Online (Sandbox Code Playgroud)
我会在课堂上声明一个@propertyfor popupQuery,并用它来跟踪行动表.
- (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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1894 次 |
| 最近记录: |