在NSThread问题上调用带有两个参数的选择器 [英] calling selector with two arguments on NSThread issue

查看:247
本文介绍了在NSThread问题上调用带有两个参数的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含多个参数的Thread。
有可能吗?
我有这个函数:

I'd like to make a Thread with multiple arguments. Is it possible? I have the function:


-(void) loginWithUser:(NSString *) user password:(NSString *) password {
}

我想将此函数称为选择器:

And I want to call this function as a selector:



[NSThread detachNewThreadSelector:@selector(loginWithUser:user:password:) toTarget:self withObject:@"someusername" withObject:@"somepassword"]; // this is wrong



如何在此detachNewThreadSelect函数上传递onObject参数的两个参数?


How to pass two arguments on withObject parameter on this detachNewThreadSelect function?

有可能吗?

推荐答案

你需要通过传递给withObject的对象中的额外参数如下:

You need to pass the extra parameters in an object passed to withObject like so:

NSDictionary *extraParams = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"user",@"password",nil] andKeys:[NSArray arrayWithObjects:@"valueForUser",@"valueForPassword",nil]]

[NSThread detachNewThreadSelector:@selector(loginWithUser:) toTarget:self withObject:extraParams]; 

这篇关于在NSThread问题上调用带有两个参数的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆