Pregunta

Estoy implementando una vista de alerta simple con el indicador de actividad para mostrar al usuario mientras la aplicación realiza la restauración de la base de datos. Todo está bien, excepto que no puedo ver la vista de alerta, a menos que comente la línea de despedida automática (la última aquí).

Ok, la restauración de la base de datos es bastante rápida, pero aún así esperaría verla incluso si por un instante, ¿no? Puedo ver que la pantalla se vuelve un poco más oscura durante la animación, pero eso es todo. También intenté poner un bucle for para extender el tiempo, el tiempo se extiende pero aún no hay una vista de alerta.

No hay nada de malo en la forma en que se llama la vista de alerta, ya que si comento la descarga, puedo verlo ... solo para siempre. ¿Alguien tiene una idea aquí?

Antes de que nadie lo diga, intenté cambiar el delegado de alertview a self Como se publica aquí, pero no ayudó.

// First we prepare the activity indicator view to show progress indicator
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[activityView setFrame:CGRectMake(121.0f, 50.0f, 37.0f, 37.0f)];
[activityView startAnimating];

// Then we put it in an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alertView addSubview:activityView];
[alertView show];

// Finally we operate the restore
[[SQLManager sharedSQL] restoreDatabase:[restoreDatabaseURL path]];

// And we can dismiss the alert view with the progress indicator
[alertView dismissWithClickedButtonIndex:0 animated:NO];
¿Fue útil?

Solución

No estoy seguro por qué Esto sucede, pero también lo encuentro de vez en cuando. Una forma en que he conseguido algo como esto para funcionar es usando performSelector:withObject:afterDelay: En la siguiente llamada, como esta:

// First we prepare the activity indicator view to show progress indicator
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[activityView setFrame:CGRectMake(121.0f, 50.0f, 37.0f, 37.0f)];
[activityView startAnimating];

// Then we put it in an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alertView addSubview:activityView];
[alertView show];

// Finally we operate the restore
// [[SQLManager sharedSQL] restoreDatabase:[restoreDatabaseURL path]];
[[SQLManager sharedSQL] performSelector:@selector(restoreDatabase:) withObject:[restoreDatabaseURL path] afterDelay:0.25];


// And we can dismiss the alert view with the progress indicator
[alertView dismissWithClickedButtonIndex:0 animated:NO];

performSelector Documentación

Otros consejos

Parece que se descarta casi instantáneamente. Si agrega un bucle for, es probable que congele todos los demás cálculos, lo que significa que su vista de actividad no aparecerá hasta que se rompa el bucle.

Puede intentar usar un NSTIMER para llamar a otra función para determinar si la restauración está completa o no;

// Setup our the timer
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                  target:self 
                                                selector:@selector(checkRestore)
                                                userInfo:nil
                                                 repeats:YES];


// Timer function checking for completion
-(void)checkRestore {
    if (restore is complete) {
        [alertView dismissWithClickedButtonIndex:0 animated:NO];
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top