我想知道如何在3秒后消失消息? 谢谢,
UIAlertController *alert_carbu_reglementaire = [UIAlertController
alertControllerWithTitle:@"ATTENTION"
message:@"Le résultat ne prend pas en compte la quantité réglementaire"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert_carbu_reglementaire animated:YES completion:nil];
答案 0 :(得分:2)
您可以使用两种有用的工具:首先,您可以使用以下performSelector
方法之一轻松延迟执行:
// after present, wait 3 seconds and perform a selector
[self presentViewController:alert_carbu_reglementaire animated:YES completion:nil];
[self performSelector:@selector(dismissTheAlert) withObject:nil afterDelay:3.0];
第二个事实是视图控制器可以使用dismisViewController...
- (void) dismissTheAlert {
[self dismissViewControllerAnimated:YES completion:^{}];
}
答案 1 :(得分:0)
尝试使用GC电源在3秒后调用setMessage。 看看这个例子:
Swift 2.3
let delay = 3.0
let delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)))
dispatch_after(delayInNanoSeconds, dispatch_get_main_queue()) {
alert_carbu_reglementaire.message = ""
}
目标-C
double delay = 2.0;
dispatch_time_t delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[alert_carbu_reglementaire setMessage:@""];
});
请确保您不会造成内存泄漏。