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];
开发者_如何学C [alertView show];
[alertView release];
i want to dimiss the alerview after it's showing for some time,but when the alertview has no button,it doesn't work if i invoked -dismissWithClickedButtonIndex:animated: method
and-performSelector:withObject:afterDelay:
is there any other way to dismiss it ?
thanks for any ideas!
-(void)xx {
[self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
that's it.i fix it
Use 10 seconds delays to dismiss
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
}];
});
In Xamarin.iOS / Monotouch this worked for me:
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);
}
Remember that if an async method is called from a background thread (not the main UI thread) then InvokeOnMainThread would still be required. This just means that you call the above method like this:
BeginInvokeOnMainThread(() =>
{
ShowToast(message);
});
update to the answer above as UIAlertView
is deprecated
Answer At this Link
the 2nd function should be like this
-(void)dismissAlertView:(UIAlertController *)alertView{
[alertView dismissViewControllerAnimated:YES completion:nil];
}
精彩评论