performSelectorOnMainThread

performSelectorOnMainThread

本文介绍了iphone - performSelectorOnMainThread与返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方法:

- (NSMutableArray *)getElements:(NSString *)theURL;

我想知道是否有一种方法使用performSelectorOnMainThread调用该方法,返回值。到目前为止,我尝试过:

And I wanted to know if there is a way to call that method using performSelectorOnMainThread so that I can get the return value. So far, I've tried with:

myArray = [object performSelectorOnMainThread:@selector(getElements:)
                                   withObject:url waitUntilDone:YES];

但它不工作,因为performSelectorOnMainThread返回void。我如何解决这个问题?

but it doesn't work, since performSelectorOnMainThread returns void. How could I solve this?

推荐答案

欢迎来到我的朋友的多线程环境。

Welcome to a multi-threaded environment my friend.

您需要将返回值存储在实例变量中,或通过引用通过 withObject 参数传递对象:

You'll need to store the return value in an instance variable or pass in an object by reference through the withObject parameter:

NSMutableDictionary *myDict;

[object performSelectorOnMainThread:@selector(getElements:)
                                   withObject:&myDict waitUntilDone:YES];

您的方法原型应如下所示:

Your method prototype should now look like this:

- (void)getElements:(NSMutableDictionary **)objects;

这篇关于iphone - performSelectorOnMainThread与返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 01:35