
这是我知道使进程不在目标c的主线程中执行的唯一方法
[self performSelectorInBackground:@selector(callXml) withObject:self];
所以我把我的电话封装成一个函数
- (voID)callXml{ [RXMLElement elementFromURL:[NSURL URLWithString:indXML]]; } 现在我必须使字符串indXML成为函数的参数,以便根据需要调用不同的xml.
就像是
- (voID)callXml:(Nsstring *) name{ [RXMLElement elementFromURL:[NSURL URLWithString:indXML]]; } 在这种情况下,对performSelector的调用如何改变?如果我以通常的方式做到这一点,我会得到语法错误:
[self performSelectorInBackground:@selector(callXml:@"test") withObject:self];解决方法
[self performSelectorInBackground:@selector(callXml:) withObject:@"test"];
IE:你传入的内容与withObject:成为你的方法的参数.
正如您感兴趣的那样,您可以使用GCD来做到这一点:
dispatch_async(dispatch_get_global_queue(disPATCH_QUEUE_PRIORITY_DEFAulT,0),^{ [self callXml:@"test"]; // If you then need to execute something making sure it's on the main thread (updating the UI for example) dispatch_async(dispatch_get_main_queue(),^{ [self updateGUI]; });}); 总结 以上是内存溢出为你收集整理的ios – 如何使用带参数的函数调用performSelectorInBackground?全部内容,希望文章能够帮你解决ios – 如何使用带参数的函数调用performSelectorInBackground?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)