Pregunta

Aquí está mi situación: estoy haciendo solicitudes HTTP sincrónicas para recopilar datos, pero de antemano quiero colocar una vista de carga dentro de la vista del título de la barra de navegación. Después de que termine la solicitud, quiero devolver el TitleView a Nil.

[self showLoading];        //Create loading view and place in the titleView of the nav bar.
[self makeHTTPconnection]; //Creates the synchronous request
[self endLoading];         //returns the nav bar titleView back to nil.

Sé que la vista de carga funciona porque se muestra la solicitud por encima de la vista de carga.

Mi problema: debería ser obvio en este momento, pero básicamente quiero retrasar el[self makeHTTPconnection] funcionar hasta que [self showLoading] ha completado.

Gracias por tu tiempo.

¿Fue útil?

Solución

No puedes hacer eso en un enfoque sincrónico. Cuando enviarías Self Showloading Mensaje, la interfaz de usuario no se actualizaría hasta que termine todo el método, por lo que ya terminaría las otras dos tareas (CONNECCIÓN MAKEHTTP y end porción). Como resultado, nunca verá la vista de carga.

Una posible solución para esta situación sería funcionar simultáneamente:

[self showLoading];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_sendRequest) object:nil];
[queue addOperation:operation];
[operation release];

Entonces debe agregar el método * _sendRequest *:

- (void)_sendRequest
{
    [self makeHTTPConnection];
    //[self endLoading];
    [self performSelectorOnMainThread:@selector(endLoading) withObject:nil waitUntilDone:YES];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top