1

我有這樣的代碼,它工作完全按照期望:警告: 「否 '-renderInContext' 的方法找到了」

UIGraphicsBeginImageContext(self.bounds.size); 
[self.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

然而,對於這一行:

[self.layer renderInContext:UIGraphicsGetCurrentContext()]; 

我得到警告(不是錯誤):

找不到'-renderInContext'方法。

如果實際上該方法正在工作,我該如何得到此警告?如果我只是簡單地評論這一行,我的代碼就會失敗;所以顯然這條線和方法實際上是有效的。

回答

7

您需要爲CALayer - #import <QuartzCore/QuartzCore.h>添加對頭文件的引用。您可能還需要將QuartzCore.framework添加到您的項目中。

3

這是說這是因爲編譯器無法找到該方法的定義。您需要添加以下行:

#import <QuartzCore/QuartzCore.h> 

.m文件的開頭。您可能還需要將QuartzCore框架添加到您的項目中。

(您的應用工作的原因是該方法在運行時可用)