i’m trying to get directory file listing from my ftp server using Chilkat library.
In this case, i want to animating a UIActivityIndicatorView when the process is running. But the problem is, the UIActivityIndicatorView never start to animate. The code I use is :
[self.activityIndicator startAnimating];
[selfgetListFromPath:ftpPath withConnection:ftpConnect];
[self.activityIndicator stopAnimating];
activityIndicator is an object of UIActivityIndicatorView, ftpPath is a NSString of my file path in FTP server, and getListFromPath is the method for getting list from FTP server using Chilkat algorithm, ftpConnect is an object of FTP Connection Class.
I was try to use NSRunLoop before called getListFromPath function, so I changed my code into :
[self.activityIndicator startAnimating];
BOOL waitingOnProcessing = YES;
NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
while (waitingOnProcessing && [currentRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {
}
[self getListFromPath:ftpPath withConnection:ftpConnect];
[self.activityIndicator stopAnimating];
this make the activityIndicator animating, but the getListFromPath never fired. After a trial, i choosed to changed again my code into :
[self.activityIndicator startAnimating];
BOOL waitingOnProcessing = YES;
NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
while (waitingOnProcessing && [currentRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {
waitingOnProcessing = NO;
}
[self getListFromPath:ftpPath withConnection:ftpConnect];
[self.activityIndicator stopAnimating];
it make the activityIndicator animating, and also fired the getListFromPath function. But i’m doubt with this code, am i right with this code? or maybe there is a bad practice for using NSRunLoop?
can somebody tell me
Thank you
This code runs as in a “black box” :
So UI updates occur when your method returns, and you won’t see the update.
What you need to do is startAnimating your activity indicator, then start your
getListFromPathin another thread. When that method terminates, you call back your main thread telling it to stopAnimating the indicator.Use this methods:
to start your getListFromPath thread, then when it’s done, call
to give the control back to the main thread, which will stop the spinner animation.