Uiactionsheet is the Select button item that pops up in iOS, you can add multiple items and add click events for each item.
Use
1. Need to implement Uiactionsheetdelegate protocol
@interface Njwisdomcarddetailviewcontroller () <UIActionSheetDelegate>@end
2. Pop-Up selection button box
- (void) showsheet{Uiactionsheet*actionsheet =[[Uiactionsheet alloc] Initwithtitle:@"Title,nil when not displayed" Delegate: Self cancelbuttontitle:@"Cancel"Destructivebuttontitle:@"Determine"Otherbuttontitles:@"First Item",@"Second Item", nil]; Actionsheet.actionsheetstyle=Uiactionsheetstyleblackopaque; [Actionsheet ShowInView:self.view];}
Parameter explanation:
- Actionsheet. Actionsheetstyle = Uiactionsheetstyleblackopaque;//Set style
- The Cancelbuttontitle and Destructivebuttontitle are the two buttons of the system belt.
- Otherbuttontitles is a defined item, note that the last parameter is nil.
- [Actionsheet Showinview: Self. View]; This line of statement means that the action sheet is displayed in the current view.
Style is set and the action form also supports three styles:
- Uiactionsheetstyledefault // Default style: White text on gray background
- Uiactionsheetstyleblacktranslucent // transparent black background, white text
- Uiactionsheetstyleblackopaque // black background, white text
3. Listen for the item's click event. There are corresponding methods in implementing the Protocol.
(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsinteger) buttonindex{if(Buttonindex = =0) {[Self Showalert:@"Determine"]; }Else if(Buttonindex = =1) {[Self Showalert:@"First Item"]; }Else if(Buttonindex = =2) {[Self Showalert:@"Second Item"]; }Else if(Buttonindex = =3) {[Self Showalert:@"Cancel"]; } }- (void) Actionsheetcancel: (Uiactionsheet *) actionsheet{}-(void) Actionsheet: (Uiactionsheet *) Actionsheet Diddismisswithbuttonindex: (Nsinteger) buttonindex{}-(void) Actionsheet: (Uiactionsheet *) Actionsheet Willdismisswithbuttonindex: (Nsinteger) buttonindex{}Precautions
During the development process, it is found that sometimes the last click of the Uiactionsheet is invalidated, and the last item in the upper half of the point is valid, which happens only in certain circumstances, when the Uitabbar is tried . Workaround:
This is used in ShowView, [Actionsheet showinview:[uiapplication Sharedapplication].keywindow]; or [sheet showinview:[ Appdelegate Shareddelegate].tabbarcontroller.view]; So there will be no occlusion.
Use of IOS UI Foundation -6.0 Uiactionsheet