2012-02-06 3 views
2

내 UIView 클래스의 구현을 내 View Controller로 캐스팅하려고했습니다. 그러나, 내 클래스에 대한 메서드를 호출하려고하면 "인식 할 수없는 셀렉터가 인스턴스로 전송되었습니다"가 throw됩니다. 여기 "인식 할 수없는 선택기를 인스턴스로 보내기"UIView의 경우

가 내 헤더 파일에서 무엇을하고 무엇을 : 나는 무엇입니까 위와 같이

#import "GameView.h" 

@implementation GameViewController 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    //'timerLoop' function 
    gameLoop = [NSTimer scheduledTimerWithTimeInterval: 0.025 target:self selector:@selector(timerLoop:) userInfo:nil repeats:YES]; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (void) timerLoop:(NSTimer *)timerObj { 
//so this is where I am getting the error 
    [(GameView *)self.view updateLander]; 
    [self.view setNeedsDisplay]; 
} 
- (IBAction)quitGame:(id)sender { 
    [self dismissModalViewControllerAnimated:true]; 
} 

- (IBAction)rotateLeft:(id)sender { 
    [(GameView *)self.view rotateLeft:sender]; 
} 

- (IBAction)rotateRight:(id)sender { 
    [(GameView *)self.view rotateRight:sender]; 
} 

- (IBAction)thrust:(id)sender { 
    [(GameView *)self.view thrustEngine:sender]; 
} 
@end 

@implementation GameView 

@synthesize lander_nothrust; 

-(id)initWithCoder:(NSCoder *)aDecoder{ 
    if(self == [super initWithCoder:aDecoder]){ 

     //initialize sprites 
     NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"lander" ofType:@"tiff"]; 
     self.lander_nothrust = [UIImage new]; 
     self.lander_nothrust = [UIImage imageWithContentsOfFile:imagePath]; 

     [self newGame]; 
    } 
    return self; 
} 



-(void) newGame{ 
    gstate = READY; 
    level = EASY; 
    thrusters = THRUSTERS_OFF; 
    fuel = FUEL_INITIAL; 
    loc_x = self.frame.size.width/2; 
    loc_y = self.frame.size.height/2; 

    // Set the game as RUNNING 
    gstate = RUNNING; 
} 

-(void)updateLander{ 


} 

// rotateLeft - rotate the lander left 
- (void)rotateLeft:(id)sender 
{ 
    // Do Something 
} 

// rotateRight - rotate the lander right 
- (void)rotateRight:(id)sender 
{ 
    // Do Something 
} 

// thrustEngine - fire the thruster on the engine 
- (void)thrustEngine:(id)sender 
{ 
    // Do Something 
} 

-(void)drawRect:(CGRect)rect{ 
    if(gstate != RUNNING){ 
     return; 
    } 
    [self.lander_nothrust drawAtPoint:CGPointMake(loc_x, loc_y)]; 
    self.backgroundColor = [UIColor redColor]; 
} 
@end 

: 이제

#import <UIKit/UIKit.h> 

@interface GameViewController : UIViewController{ 

    NSTimer *gameLoop; 

} 

- (IBAction)quitGame:(id)sender; 
- (IBAction)rotateLeft:(id)sender; 
- (IBAction)rotateRight:(id)sender; 
- (IBAction)thrust:(id)sender; 


@end 

typedef enum { NOTREADY, READY, RUNNING, WON, LOST, PAUSED } GameState; 
typedef enum { EASY, MEDIUM, HARD } GameDifficulty; 
typedef enum { THRUSTERS_ON, THRUSTERS_OFF } ThrusterState; 

// Declaration of other constants used to manage the physics 
static const int FUEL_INITIAL = 200; 
static const int FUEL_MAX = 200; 
static const int FUEL_BURN = 10; 
static const int MAX_INIT = 30; 
static const int MAX_SPEED = 120; 
static const int ACCELERATION_DOWN = 35; 
static const int ACCELERATION_UP = 80; 
static const double GRAVITY = 9.8; 

@interface GameView : UIView { 
@private UIImage   *plander_thrust; 
@private UIImage   *plander_nothrust; 
@private UIImage   *plander_crashed; 

    // Other game member variables 
@private GameState   gstate; 
@private GameDifficulty  level; 
@private ThrusterState  thrusters; 
@private int    fuel; 
@private int    speed_x; 
@private int    speed_y; 
@private double    rotation; 

    // Define our lander’s X and Y on-screen coordinates 
@private int loc_x; 
@private int loc_y; 
} 

@property (nonatomic, retain) UIImage *lander_nothrust; 

// Declare our class methods 
- (void) newGame; 
- (void) updateLander; 
- (void) rotateLeft:(id)sender; 
- (void) rotateRight:(id)sender; 
- (void) thrustEngine:(id)sender; 

@end 

, 여기에 내가하는 .m 파일을 사용하고있는 무슨이다 다음 코드 줄에서 오류가 발생했습니다.

나는 둘러 보았고, 내 개체에 t가 존재하지 않지만 개체 구현을 왜 보지 못하고 있는지 잘 모르겠습니다. 나는 심지어 UIView에 대한 Identity Inspector의 "GameView"클래스를 사용자 정의 클래스로 설정했습니다.

답변

9

문제는 펜촉에 있습니다. 보기의 사용자 지정 클래스를 GameView으로 설정하지 않았거나 해당 소유자에게 파일 소유자의 view 콘센트를 연결하지 않았습니다.

+0

@rob mayoff가 대답 한 바가 정확합니다. 같은 경험을 한 이래서이 문제는 – Bala

+0

좋은 소식입니다. 나는 직장에 있지만 한 번 집에 돌아 간다. 나는 그것을 시험해 볼 것이다! – Algorhythm

관련 문제