【发布时间】:2013-05-16 18:43:41
【问题描述】:
我有一个自定义的NSObject 类,做一些 FTP 工作(显示、传输...)。
这个 FTP 类有一个 downloadFiles: 方法,它在 NSOperationQueue 内启动。
我希望该方法在UITableView 中提供一些结果作为数据源。所以我决定将这些结果委托给UITableViewController。
所以 FTP 类的协议:
@protocol FTPDelegate;
..
@interface FTP...
@property (nonatomic, weak) id <FTPDelegate> delegate;
...
@protocol FTPDelegate
-(void)FTPMessageReceived: (NSString *)message;
@end
然后我将自定义 UITableViewController 声明为 FTP 类的委托:
self.myFTP = (FTP *) [self FTPManager];
self.myFTP.delegate = self;
所以当 FTP 类的 downloadFiles: 方法想要在 UITableView 中显示一些消息时,它会调用:
[[self delegate] FTPMessageReceived:@"dir created"];
UITableViewController 实现了该方法:
-(void)FTPMessageReceived: (NSString *)message {
NSUInteger index;
NSArray * indexArray;
[[self logLine] addObject: message]; // logLine is my data source
index = [[self logLine] count]-1;
NSLog(@"%u", index);
indexArray = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]];
[[self logView] insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationRight];
}
插入有效,但新行大约需要 5 秒才能显示在 UITableView 中!!
当我在 tableView:cellForRowAtIndexPath: 方法中放入一些日志时,它会立即显示。
当我将FTPMessageReceived 代码放在按钮中时(例如),UITableView 会立即显示新行!
有什么建议吗?
【问题讨论】:
标签: uitableview nsoperationqueue