Must inherit the protocol first
@interface trviewcontroller:uiviewcontroller<uialertviewdelegate,uiactionsheetdelegate>
Uialertview function implementation
-(Ibaction) clicked: (ID) Sender {
UIButton *btn = sender;
//Set Tag value
if (btn.tag==0) {
Uialertview *alertview = [[Uialertview alloc]initwithtitle:@ "Title" message:@ "message" delegate:self cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "OK", nil];
//Set Alertview style
[Alertview setalertviewstyle:uialertviewstyleloginandpasswordinput];
//Take out the TF inside the Alertview
Uitextfield *nametf = [Alertview textfieldatindex:0];
Uitextfield *PWTF = [Alertview textfieldatindex:1];
Nametf.text = @ "haha";
Pwtf.text = @ "ADFADSF";
//Pop-up window display
[Alertview show];
}else{
//uiactionsheet Initialization
Uiactionsheet *as = [[Uiactionsheet alloc]initwithtitle:@ "Title" Delegate:self cancelbuttontitle:@ "Cancel" destructivebuttontitle:@ "destructive" otherbuttontitles:@ "hehe", nil];
[As ShowInView:self.view];
}
}
//alertview Click events
-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) buttonindex{
NSLog (@ "%ld", (long) buttonindex);
//First button
if (buttonindex==1) {//OK
Uitextfield *NAMETF = [Alertview textfieldatindex:0];
Uitextfield *PWTF = [Alertview textfieldatindex:1];
NSLog (@ "%@%@", nametf.text,pwtf.text);
}else{//Cancel
}
}
Actionsheet Click events
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) buttonindex{
NSLog (@ "%ld", (long) buttonindex);
}
iOS notes Uikit_uialertview, Uiactionsheet