I have an issue for this line
ball* balle = [[ball alloc] initWithPNGFileName:ballPath andGame:game andCGRect:CGRectMake( 200, 100, 16, 16 )] ;
the issue is ' ball undeclared' with warning: 'UIImageView' may not respond to '-alloc' and warning: no '-initWithPNGFileName:andGame:andCGRect:' method found
Here's the method:
-(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 );
}
I don't understand why UIImageView can't be allocated and why I have no '-initWithPNGFileName:andGame:andCGRect:' method found
Thanks
From the code you provide it seems that you have an instance of
UIImageView
calledball
. Are you sure your Class is calledball
(Class names should begin with a capital letter, by the way) and it's.h
- file is properly included?Some background information:
alloc
is a class method, you don't send it to an instance - it's signature is something like+ (id) alloc;
(mind the plus here!) Basically, the warning says that you try to invoke the instance method alloc on your object, which would have the signature- (id) alloc;
(mind the minus here!), if it existed (which is most probably not the case). Therefore, the compiler recognizesball
not as a class name, but as an instance ofUIImageView
, which - as the warning indicates - may not respond to- (id) alloc;
. By default, the compiler assumes that unknown methods return an instance ofid
(and not ofball
as you expected), this is why it warns you that it can't find a method called-initWithPNGFileName:andGame:andCGRect
for this object.