2014-09-19 56 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

相關問題