Chilkatライブラリを使用してFTPサーバーからディレクトリファイルリストを取得しようとしています。この場合、プロセスの実行中にUIActivityIndicatorViewをアニメーション化する必要があります。ただし、問題は、UIActivityIndicatorViewがアニメーションを開始しないことです。私が使用するコードは次のとおりです。
[self.activityIndicator startAnimating];
[selfgetListFromPath:ftpPath withConnection:ftpConnect];
[self.activityIndicator stopAnimating];
activityIndicatorはのオブジェクトでありUIActivityIndicatorView
、ftpPath
FTPサーバーのファイルパスのNSStringであり、getListFromPath
Chilkatアルゴリズムを使用してFTPサーバーからリストを取得するためのメソッドでftpConnect
あり、FTP接続クラスのオブジェクトです。
関数を呼び出す前にNSRunLoopを使用しようとしたgetListFromPath
ので、コードを次のように変更しました。
[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];
これはactivityIndicator
アニメーションになりますが、getListFromPath
決して解雇されません。試用後、コードを次のように変更することにしました。
[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];
それはactivityIndicator
アニメーションを作成し、また関数を起動しgetListFromPath
ます。しかし、私はこのコードに疑問があります、私はこのコードで正しいですか?または多分NSRunLoopを使用するための悪い習慣がありますか?誰か教えてもらえますか
ありがとうございました