我厌倦了在Xcode中使用此代码来修改图片,但没有任何变化

    UIImage *myimage= (UIImage *)[tableView viewWithTag:tag+1];

    NSURL *imageURL = [NSURL URLWithString:@"https://38.media.tumblr.com/avatar_c0deb2e1dd65_128.png"];


    dispatch_async(dispatch_get_global_queue(0,0), ^{
        NSData * data = [[NSData alloc] initWithContentsOfURL: imageURL];
        if ( data == nil ){
            return;

        }
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"dddddddd");

   __block myimage = [UIImage imageWithData: data];
        });

    });


谢谢。

最佳答案

您的代码是错误的。应该是这样的:

UIImageView *myImageView= (UIImageView *)[tableView viewWithTag:tag+1];

NSURL *imageURL = [NSURL URLWithString:
  @"https://38.media.tumblr.com/avatar_c0deb2e1dd65_128.png"];
dispatch_async(dispatch_get_global_queue(0,0), ^
{
    NSData * data = [[NSData alloc] initWithContentsOfURL: imageURL];
    if ( data == nil )
    {
        return;
    }
    dispatch_async(dispatch_get_main_queue(), ^
    {
        NSLog(@"dddddddd");

        UIImage *myImage = [UIImage imageWithData: data];
        myImageView.image = myImage;
    });
});

关于ios - 使用URL在Xcode中修改UIImageview,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33920957/

10-10 01:28