1. m file in Viewcontroller, comply with <UIAlertViewDelegate> Agent agreement
@interface moboviewcontroller () <UIAlertViewDelegate>
2. Implement Uialertview in-(void) Viewdidload method
1- (void) Viewdidload2 {3 [Super Viewdidload];4 5 //1. Initialize Alertview6Uialertview *altview = [[Uialertview alloc]initwithtitle:[self Alttitle] message:[self AltMSG]Delegate: Self cancelbuttontitle:[self cancelbtntitle] otherbuttontitles:[self Otherbtntitle], nil];7 //2. Display Alertview8 [Altview show];9 Ten}
3, continue to implement other methods, return to the various headings and monitoring button click event Agent method
1 //return title2-(NSString *) alttitle{3 return @"Offline Notification";4 }5 6 //returns the body of the message7-(NSString *) altmsg{8 return @"your account is logged off-site, the password may be leaked, it is recommended to go to http://mobodemy.com to modify. ";9 }Ten One //Returns the Exit button caption A-(NSString *) Cancelbtntitle { - return @"Exit"; - } the - //return Login button title --(NSString *) Otherbtntitle { - return @"Re-login"; + } - + //Monitor Click-Time Proxy Method A- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) Buttonindex at { -NSString *btntitle =[Alertview Buttontitleatindex:buttonindex]; - if([Btntitle isequaltostring:[self Cancelbtntitle]]) { -NSLog (@"you clicked the exit"); - } - Else if([Btntitle isequaltostring:[self Otherbtntitle]]) { inNSLog (@"you clicked the Re-login button"); - } to}
Ios7_ how to implement Uialertview and monitor click events