我有以下方法:
- (NSMutableArray *)getElements:(NSString *)theURL;
我想知道是否有办法使用performSelectorOnMainThread 调用该方法,以便我可以获得返回值。到目前为止,我已经尝试过:
myArray = [object performSelectorOnMainThread:@selector(getElements:)
withObject:url waitUntilDone:YES];
但是它不起作用,因为performSelectorOnMainThread返回void。我该如何解决这个问题?
最佳答案
欢迎来到多线程环境,我的 friend 。
您需要将返回值存储在实例变量中,或者通过 withObject
参数通过引用传入对象:
NSMutableDictionary *myDict;
[object performSelectorOnMainThread:@selector(getElements:)
withObject:&myDict waitUntilDone:YES];
您的方法原型(prototype)现在应如下所示:
- (void)getElements:(NSMutableDictionary **)objects;
关于iphone - 带有返回值的performSelectorOnMainThread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3346100/