2014-09-19 61 views
0

我想将uiimage设置为函数范围之外的变量.i尝试了下面的代码,但它不起作用。以下代码用于自定义可用视图单元类。所以我不能分配和初始化它。因为这将导致初始化它显示/滚动每次细胞如何将ui映像复制到另一个变量?

uiimage *img; 
    [manager downloadWithURL:[NSURL URLWithString:friendData.picUrl] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) { 

    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { 

     img =image; ////this is not working !! 



    }]; 


    dispatch_async(dispatch_get_main_queue(), ^{ 


     [cell.profileImage setImage:img]; //and off course this wont work too 

    }); 
+0

ü可以张贴一些代码function.try的地方是'的UIImage *图像1 '被宣布? – sreekanthk 2014-09-19 07:11:40

+0

也许你需要在分配UIImage值之前启动它?尝试UIImage * img = [[UIImage alloc] init]; – felixwcf 2014-09-19 07:24:19

回答

0

您可以与任何其他初始化方法初始化image1: 试试这个:

image1 = UIImage.init(CGImage:image.CGImage); 

初始化方法将创建新的对象根据this文件。

我还没试过。请尝试它是否有效。如果不工作只是评论我,我可能会找到其他解决方案。

0

您需要分配图像1,使其工作出此

image1 = [[UIImage alloc] initWithCGImage: image.CGImage]; 
1

我想你可能只需要设置__block UIImage image = nil;

+0

好..但我应该在哪里放这个代码? – 2014-09-19 08:09:11

+0

替换为:uiimage * img; – 2014-09-19 08:10:19

+1

它工作:)但你可以解释一下为什么它的工作?我是新来的“块” – 2014-09-19 08:12:14

相关问题