我正在尝试使用 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 有不好的做法?谁能告诉我
谢谢