だから、Objective-C で Circle クラスを作ろうとしています。Java と OOP、および Objective-C を少し知っていますが、クラスが初期化されない理由がわかりません。Circle.h は次のとおりです。
#import <Foundation/Foundation.h>
#import "Image.h"
@interface Circle : NSObject
{
Image *img;
CGPoint pos;
}
-(id) init;
-(void) draw;
@end
これが Circle.m ファイルです。
#import "Circle.h"
@implementation Circle
-(id) init{
self = [super init];
if (self != nil) {
img = [[Image alloc] initWithImage:[UIImage imageNamed:@"circle.png"]];
pos = CGPointMake((CGFloat)200, (CGFloat)200);
}
img = [[Image alloc] initWithImage:[UIImage imageNamed:@"circle.png"]];
pos = CGPointMake((CGFloat)200, (CGFloat)200);
return self;
}
-(void) draw{
[img renderAtPoint: pos centerOfImage: YES];
}
@end
次に、メインクラスで次のように呼び出します。
//player is the name of the circle object (Circle *player;)
[player init];
そして、私のレンダーメソッドで私は呼び出します:
[player draw];
アプリを実行すると、画像が描画されません。