【问题标题】:How to Pass a parameter to a method from NSTread?如何从 NSTread 将参数传递给方法?
【发布时间】:2011-07-06 16:49:11
【问题描述】:

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

}

【问题讨论】:

    标签: iphone objective-c methods nsthread


    【解决方案1】:

    您可能需要将selector:@selector(getFriendPic) 替换为selector:@selector(getFriendPic:)。你漏掉了一个冒号。

    【讨论】:

      猜你喜欢
      • 2011-07-18
      • 2021-05-26
      • 2014-07-29
      • 1970-01-01
      • 2021-12-13
      • 2012-02-23
      • 2011-07-25
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多