您的位置:首页 > 移动开发 > IOS开发

iOS中消息框提示的出现与自动消失

2015-05-28 19:40 429 查看


使用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];

注意:此方法会强制吸引用户注意力焦点,适用于重要的提示信息。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息