1
所以我想在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];
當我運行我的應用程序時,ima ge不會畫,有幫助嗎?
好吧,工作!我只需要確保我這麼做(來自Java背景)非常感謝! – TennisMaster 2012-07-30 19:44:14