我正在尝试在调用 Web 服务时进行加载视图...我已经尝试过:
-(void) viewDidLoad {
[NSThread detachNewThreadSelector:@selector(workerThread) toTarget:self withObject:nil];
//here I call the thread before call web service
}
-(void) workerThread {
[viewLoading setHidden:NO];
[NSThread detachNewThreadSelector:@selector(threadAnimacao) toTarget:self withObject:nil];
}
-(void) threadAnimacao { //call this function is ok, but the timerLoadingEvento only is called after the call webservice ends
contadorLoading = 0;
nVoltas = 0;
nEspera = 0;
timerLoading = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerLoadingEvento:) userInfo:nil repeats:YES];
}
-(void)timerLoadingEvento:(NSTimer *)theTimer{
UIImageView *img = imgLoading;
if (nEspera == 0) {
if(contadorLoading == 0)
[img setImage:[UIImage imageNamed:@"frame_01.png"]];
else if(contadorLoading == 1)
[img setImage:[UIImage imageNamed:@"frame_02.png"]];
else if(contadorLoading == 2)
[img setImage:[UIImage imageNamed:@"frame_03.png"]];
else if(contadorLoading == 3)
[img setImage:[UIImage imageNamed:@"frame_04.png"]];
else if(contadorLoading == 4)
[img setImage:[UIImage imageNamed:@"frame_05.png"]];
else if(contadorLoading == 5)
[img setImage:[UIImage imageNamed:@"frame_06.png"]];
else if(contadorLoading == 6)
[img setImage:[UIImage imageNamed:@"frame_07.png"]];
else if(contadorLoading == 7)
[img setImage:[UIImage imageNamed:@"frame_08.png"]];
else if(contadorLoading == 8)
[img setImage:[UIImage imageNamed:@"frame_09.png"]];
}
contadorLoading++;
nVoltas++;
if(nEspera != 0)
nEspera++;
if(nEspera>250) {
nEspera = 0;
contadorLoading = 0;
nVoltas = 0;
}
if(contadorLoading == 8)
contadorLoading = 0;
if(nVoltas == 9)
nEspera = 1;
}