使用UIAlertView和NSTimer可以很轻松地实现消息框提示的出现与自动消失
- (void)timeFireMethod:(NSTimer *)theTimer{
UIAlertView *alert = (UIAlertView *)[theTimer userInfo];
[alert dismissWithClickedButtonIndex:0 animated:NO];
alert = NULL;
}
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:nil
message:@"ok!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil,nil];
[NSTimer scheduledTimerWithTimeInterval:1.0f //调节出现的时间
target:self
selector:@selector(timeFireMethod:)
userInfo:alertview
repeats:NO];
[alertview show];
注意:此方法会强制吸引用户注意力焦点,适用于重要的提示信息。