[英]Is there a way to dismiss an no button UIalertView after some time?
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"tittle"
message:@""
delegate:self
cancelButtonTitle:@""
otherButtonTitles:nil];
[alertView show];
[alertView release];
我想在显示一段时间后取消alerview,但是当alertview没有按钮时,如果我调用-dismissWithClickedButtonIndex:animated: method
和performSelector:withObject:afterDelay:
它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);
});
deprecated
UIAlertView
更新至以上答案。
第二个功能应该是这样的
-(void)dismissAlertView:(UIAlertController *)alertView{
[alertView dismissViewControllerAnimated:YES completion:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.