2012-07-30 2 views
1

그래서 Objective-C에서 Circle 클래스를 만들려고합니다. 나는 Java와 OOP, Objective-C를 조금 알고 있지만, 왜 클래스가 초기화되지 않는지 알 수 없다. 여기 Circle.m 파일입니다개체 초기화되지 않음

#import <Foundation/Foundation.h> 
#import "Image.h" 

@interface Circle : NSObject 
{ 
    Image *img; 
    CGPoint pos; 
} 

-(id) init; 
-(void) draw; 


@end 

과 :

#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]; 

그리고 내 렌더링 방법 여기 Circle.h입니다 전화 :

[player draw]; 

내 앱을 실행할 때 ima 도움이 필요하지 않습니까?

답변

1

당신은 아마하고 싶은 말 :

player = [[Circle alloc] init]; 

보다는 [player init], 플레이어는 무기 호 (회원의 기본값) 인 경우, 후자는 아무것도 할 것이기 때문이다.

+0

잘 했어! 나는 그 일을 확실히해야한다. (자바 배경에서 나온다.) 고맙다! – TennisMaster

관련 문제