(UIImageView的可能不是「-alloc」響應),我有一個問題,對於此行問題初始化一個自定義類
ball* balle = [[ball alloc] initWithPNGFileName:ballPath andGame:game andCGRect:CGRectMake(200, 100, 16, 16)] ;
的問題是「未申報球」有警告:「UIImageView的」可能不響應「-alloc」和警告:沒有「-initWithPNGFileName:andGame:andCGRect:」方法找到
這裏的方法:
-(id) initWithPNGFileName:(NSString *) filename andGame: (Game*) game andCGRect: (CGRect) imagerect_ {
[super init];
CGDataProviderRef provider;
CFStringRef path;
CFURLRef url;
const char *filenameAsChar = [filename cStringUsingEncoding:[NSString defaultCStringEncoding]]; //CFStringCreateWithCString n'accepte pas de NSString
path = CFStringCreateWithCString (NULL, filenameAsChar, kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, NO);
CFRelease(path);
provider = CGDataProviderCreateWithURL (url);
CFRelease (url);
image = CGImageCreateWithPNGDataProvider (provider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease (provider);
imageRect = imagerect_ ;
[game addToDraw: self] ;
[game addToTimer : self] ;
return self ;
}
-(void) draw: (CGContextRef) gc
{
CGContextDrawImage (gc, imageRect, image);
}
我不明白爲什麼的UIImageView無法分配,爲什麼我有沒有'-initWit hPNGFileName:andGame:andCGRect:」方法找到
感謝
嗨..你可以發佈'ball'類的`.h`文件嗎? – EmptyStack 2011-02-17 03:45:40