This is usually the case. Create alert and add an agent
// Create a Uialertview and show it Delegate : Self cancelbuttontitle:str otherbuttontitles:nil]; [Alertview show]; -(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{ nslogd ( @ "%ld", (long) buttonindex);}
if it looks like the bottom of the writing is much more [[[Uialertview alloc] Initwithtitle:@"Delete this Item?"message:@"Is you sure want to delete this really important thing?"Cancelbuttonitem:[ributtonitem Itemwithlabel:@"Yes"action:^{ //Handle "Cancel"}] Otherbuttonitems:[ributtonitem Itemwithlabel:@"Delete"action:^{ //Handle "Delete"}], nil] show];
Got lazy cancer just go to this link download directly or look down. Highly customizable https://github.com/jivadevoe/UIAlertView-Blocks
is to implement the method when you want to implement the Block method xxx.action (), of course, to pre-determine if there is this method if (xxx.action) //This is a non-parametric closure if you want to write a parameter closure see The wording of closures
////HFLittleHelperButton.h//Dailylife////Created by HF on 15/12/5.////#import"HFBorderLineButton.h"@interface hflittlehelperbutton:hfborderlinebutton@property (copy, nonatomic)void(^action) ();+ (ID) buttonwithnormaltitle: (NSString *) title action: (void(^) (void) ) Action;@end
The key method has been made to highlight the emphasis that should be seen on how to invoke this. The action method can also get the BTN object of this implementation where needed and then trigger. Action () can be
////hflittlehelperbutton.m//Dailylife////Created by HF on 15/12/5.////#import"HFLittleHelperButton.h"@implementation Hflittlehelperbutton+ (ID) buttonwithnormaltitle: (NSString *) title action: (void(^) (void)) action{Hflittlehelperbutton*BTN =[Hflittlehelperbutton Buttonwithtype:uibuttontypecustom]; [Btn Settitle:title Forstate:uicontrolstatenormal]; [Btn Settitlecolor:color_theme_green Forstate:uicontrolstatenormal]; [btn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatehighlighted]; [btn setbackgroundimage:[huofarutils Createimagewithcolor:color_theme_green] Forstate:uicontrolstatehig Hlighted]; Btn.backgroundcustomcolor=Color_theme_green; Btn.layer.cornerRadius=2; Btn.layer.masksToBounds=YES; Btn.layer.borderColor=Color_theme_green. Cgcolor; Btn.layer.borderWidth=1; [btn Setaction:action];
[Btn addtarget:self Action: @selector (btnblockaction:) forcontrolevents:uicontroleventtouchupinside];
Return
-(void) Btnblockaction: (Hflittlehelperbutton *) btn{
if (btn.action)
Btn.action ();
}
@end
Actual combat:
Hflittlehelperalertview *alert = [[Hflittlehelperalertview alloc]initwithblockexpression: Helperalertviewexpressiontypeplease Title:@"Title name"Message@" Good study day day up Good study day day up Good study day day up Good study day day up good study day up"Withview:nil Cancelbutton:[hflittlehelperbutton Buttonwithcanceltitle:@"Cancel"action:^{NSLog (@"XXXXXX"); }] Otherbuttons:[Hflittlehelperbutton buttonwithnormaltitle: @ "111111" action:^{NSLog (@ "111111" );}],[Hflittlehelperbutton buttonwithnormaltitle: @ "222222" action:^{NSLog (@ "222222" );}],[Hflittlehelperbutton buttonwithnormaltitle: @ "333333" action:^{NSLog (@ "333333" );}], nil]; [Alert Showhelperalertviewview];
IOS tries to replace delegate implementation with block closures