How to Pass a parameter to a method from NSTread?

空扰寡人 提交于 2019-12-11 18:00:01

问题


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];

}

回答1:


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



来源:https://stackoverflow.com/questions/6600081/how-to-pass-a-parameter-to-a-method-from-nstread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!