如何从NSTread将参数传递给方法? [英] How to Pass a parameter to a method from NSTread?

查看:75
本文介绍了如何从NSTread将参数传递给方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在NSTread中获取一个字符串作为参数,现在我必须将此字符串传递给下一个方法,所以我该怎么做?我的代码如下: 调用方法并传递对象

i am getting a string as parameter in an NSTread now i have to pass this string to next method so how can i do it? my code is given below: calling method and passing an object

[self friendPic:user.userId];

我的NSTread是这个

-(void)friendPic:(NSString *)friendID{
    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(getFriendPic) object:friendID];
    [thread start];
    [thread release];

}

-(void)getFriendPic:(NSString *)_friendID{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];



    NSString *str =[NSString stringWithFormat:@"http://www.3softcanada.com/ipictures/Image%@.png",_friendID];

    NSLog(@"url is%@", str);
    NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]];

    UIImage *theImage= [[UIImage alloc] initWithData:imageData ];
    avatar.image = theImage;

    [pool release];

}

推荐答案

您可能需要将selector:@selector(getFriendPic)替换为selector:@selector(getFriendPic:).你错过了一个冒号.

You probably need to replace selector:@selector(getFriendPic) with selector:@selector(getFriendPic:). You missed a colon.

这篇关于如何从NSTread将参数传递给方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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