有没有办法在一段时间后解散uialertview?
-
10-10-2019 - |
题
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"tittle"
message:@""
delegate:self
cancelButtonTitle:@""
otherButtonTitles:nil];
[alertView show];
[alertView release];
我想在展示一段时间后将其显示在Alerview之后 -dismissWithClickedButtonIndex:animated: method
和-performSelector:withObject:afterDelay:
还有其他方法可以驳回它吗?感谢您的任何想法!
解决方案
-(void)xx {
[self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
就是这样。我解决了
其他提示
使用10秒的延误来解散
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alertController dismissViewControllerAnimated:YES completion:^{
p\Perform Action after dismiss alertViewController
}];
});
在Xamarin.ios / Monotouch中,这对我有用:
private async Task ShowToast(string message, UIAlertView toast = null)
{
if (null == toast)
{
toast = new UIAlertView(null, message, null, null, null);
toast.Show();
await Task.Delay(2000);
await ShowToast(message, toast);
return;
}
UIView.BeginAnimations("");
toast.Alpha = 0;
UIView.CommitAnimations();
toast.DismissWithClickedButtonIndex(0, true);
}
请记住,如果从背景线程(不是主UI线程)调用异步方法,则仍然需要InvoKeonMainThread。这只是意味着您将上述方法称为这样:
BeginInvokeOnMainThread(() =>
{
ShowToast(message);
});
更新上面的答案 UIAlertView
是 deprecated
在此链接上回答
第二个功能应该像这样
-(void)dismissAlertView:(UIAlertController *)alertView{
[alertView dismissViewControllerAnimated:YES completion:nil];
}
不隶属于 StackOverflow