本文介绍了从NSOperation返回数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建大量的 NSOperation
s(子类),它们对一堆数据进行排序。当它们完成后,我希望它们返回那些数据并将其放入可变数组或其他内容中。订单无关紧要。
I'm creating a lot of NSOperation
s (subclasses) that sort through a bunch of data. When they're done, I'd like them "return" that data and put it into a mutable array or something. Order doesn't matter.
这样的事情是可能的吗?
Is something like this is possible?
推荐答案
不确定。在NSOperation子类中声明委托。然后在完成操作后
Sure. Declare a delegate in NSOperation subclass. Then after finish of operation
if([self.delegate respondsToSelector:@selector(YourDelegate:)]) {
[(NSObject *)self.delegate performSelectorOnMainThread:@selector(YourDelegate:) withObject:self waitUntilDone:NO];
}
在用户界面
-(void)YourOperationDidFinish:(YourOperation *)downloader {
if(downloader.downloadItem) {
// processing with your object
}
}
这篇关于从NSOperation返回数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!