如何从 NSTread 将参数传递给方法?
我在 NSTread 中获取一个字符串作为参数,现在我必须将该字符串传递给下一个方法,那么我该怎么做呢?我的代码如下: 调用方法并传递对象
[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];
}
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];
my NSTread
is this
-(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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要将
selector:@selector(getFriendPic)
替换为selector:@selector(getFriendPic:)
。你漏掉了一个冒号。You probably need to replace
selector:@selector(getFriendPic)
withselector:@selector(getFriendPic:)
. You missed a colon.