What is an operation form? Figure:
You can see from the figure.
UIActionSheet* mySheet = [[UIActionSheet alloc] initWithTitle:@"ActionChoose" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"OK", nil]; [mySheet showInView:self.view];
Similar to uialertview, we also process the actions after the button is pressed in the delegate method. Remember to add uiactionsheetdelegate to the delegate class.
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{ //}- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ //}-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ //}-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{ //}
Did you see the red button? It is a so-called destroy button supported by actionsheet, which plays a warning role on an action of a user,
For example, permanently delete a message or log. If you specify a destroy button, it will be highlighted in red:
mySheet.destructiveButtonIndex=1;
Similar to the navigation bar, the operation form also supports three styles:
Uiactionsheetstyledefault // default style: The white text uiactionsheetstyleblacktranslucent is displayed on the gray background // The transparent black background, the white text uiactionsheetstyleblackopaque // The pure black background, and the white text
Usage example:
Mysheet. actionsheetstyle = uiactionsheetstyleblackopaque;
There are three methods to display actionsheet:
1. display in a view. You can use showinview
[Mysheet showinview: Self];
2. To align actonsheet with the toolbar or label bar, you can use showfromtoolbar or showfromtabbar.
[Mysheet showfromtoolbar: toolbar];
[Mysheet showfromtabbar: tabbar];
Release Operation form
After you press the button, the actionsheet will disappear-unless the application has a special reason, You need to press a button. The dismiss method can be used to make the form disappear:
[mySheet dismissWithClickButtonIndex:1 animated:YES];