A lot of information is used in the process of writing a program, so it is very natural to use the Uialertview control. However, the information of these hints is sometimes just a hint on the line, do not have to operate, then this prompt box will automatically disappear on the OK . uialertview eject after 2s Let it disappear automatically, two ways: (1) combine nstimer
Define Uialertview *basealert;
-(void) Performdismiss: (Nstimer *) Timer {
[Basealert dismisswithclickedbuttonindex:0 Animated:no];//important
[Basealert release];
Basealert = NULL;
}
-(void) Presentsheet {
Basealert = [[Uialertview alloc] initwithtitle:@ "Alert" message:@ "\nmessage message message" Delegate:self CancelButton Title:nil Otherbuttontitles:nil];
[Nstimer scheduledtimerwithtimeinterval:2.0f target:self selector: @selector (performdismiss:) Userinfo:nil repeats: NO];
[Basealert show]; }
(2) Use Performselector: withobject:afterdelay: Method
-(void) Dimissalert: (Uialertview *) Alert {
if (alert) {
[Alert Dismisswithclickedbuttonindex:[alert Cancelbuttonindex] animated:yes];
[Alert release];
}
}
-(void) showalert{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "title" message:@ "message" Delegate:nil Cancelbuttontitle:nil Otherbuttontitles:nil];
[alert show];
[Self performselector: @selector (dimissalert:) Withobject:alert afterdelay:2.0];
}
Ios:uialertview automatically disappears