我对这条线有疑问
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 以及为什么我没有找到 '-initWithPNGFileName:andGame:andCGRect:' 方法
谢谢