¿Hay una manera de despedir a un botón UIalertView hay después de un tiempo?
-
10-10-2019 - |
Pregunta
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"tittle"
message:@""
delegate:self
cancelButtonTitle:@""
otherButtonTitles:nil];
[alertView show];
[alertView release];
quiero dimiss la alerview después de que se está mostrando desde hace algún tiempo, pero cuando el alertview tiene ningún botón, no funciona si invoqué -dismissWithClickedButtonIndex:animated: method
and-performSelector:withObject:afterDelay:
¿hay alguna otra manera de descartarlo?
gracias por todas las ideas!
Solución
-(void)xx {
[self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
eso es lo fijan it.i
Otros consejos
Uso 10 segundos retrasos para despedir
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
}];
});
En Xamarin.iOS / MonoTouch esta trabajado para mí:
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);
}
Recuerde que si un método asíncrono se llama desde un subproceso de fondo (no el hilo principal interfaz de usuario), entonces InvokeOnMainThread seguiría siendo necesario. Esto sólo significa que se llama al método anterior como esto:
BeginInvokeOnMainThread(() =>
{
ShowToast(message);
});
actualización de la respuesta anterior es como UIAlertView
deprecated
respuesta en este enlace
la segunda función debe ser como este
-(void)dismissAlertView:(UIAlertController *)alertView{
[alertView dismissViewControllerAnimated:YES completion:nil];
}