2014-01-08 1 views
0

둘 다 상속 할 일반보기 컨트롤러 및 다른 2 개의보기를 만들려고합니다.보기 컨트롤러에서 상속 목적 c

지금이 일반이다 (내가 관련이 생각 - 뭔가 다른 필요한 경우 내가 그것을 추가 할 것) :

@interface CardGameViewController() 
@property (strong, nonatomic) IBOutlet UITabBarItem *TabSelection; 
@property (strong, nonatomic) CardMatchingGame *game; 
@property (strong, nonatomic) IBOutlet UIButton *resetButton; 
@property (weak, nonatomic) IBOutlet UILabel *scoreLable; 
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButtons; 
@end 

@implementation CardGameViewController 

- (CardMatchingGame*)game 
{ 
    if(!_game) _game = [[CardMatchingGame alloc]initWithCardCount:[self.cardButtons count] usingDeck:[self createDeck] gameMode:[self getActiveTabWithString:self.TabSelection.description]]; 
    return _game; 
} 

- (Deck*)createDeck //abstract 
{ 
    return nil; <------- Relevant generic function 
} 

이들은 언급 된 파일 상속이 개 파일은 다음과 같습니다

SetGameViewController.h :

#import "CardGameViewController.h" 

@interface SetGameViewController : CardGameViewController 

@end 

SetGameViewController.m :

#import "SetGameViewController.h" 
#import "SetCardDeck.h" 

@interface SetGameViewController() 

@end 

@implementation SetGameViewController 

-(Deck*)createDeck 
{ 
    return [[SetCardDeck alloc]init]; 
} 

@end 

및 두번째 :

PlayingCardGameViewController.h :

#import "CardGameViewController.h" 

@interface PlayingCardGameViewController : CardGameViewController 

@end 

PlayingCardGameViewController.m :

#import "PlayingCardGameViewController.h" 
#import "PlayingCardDeck.h" 

@interface PlayingCardGameViewController() 

@end 

@implementation PlayingCardGameViewController 

- (Deck*)createDeck 
{ 
    return [[PlayingCardDeck alloc]init]; 
} 
@end 

I가도 2 뷰를 전환하는 탭 막대 네비게이터있다. 두 번째 (PlayingCardGameViewController가)마다 확인하는 동안

건이며, 첫 번째 (SetGameViewController는) 내가 무슨 상관없이의 createDeck 함수가 호출되지 않습니다 의미

,

을 인스턴스화되지 않습니다.

내가 시도하는 것 : 기본보기 - (CardMatchingGame*)game 기능에 대한

배치 브레이크 포인트.

두 번째 작업보기를 시작하려고 할 때만 호출되며, 나쁜 것은 표시되지 않습니다.

누락 된 부분이 있으면 알려 주시면 추가하겠습니다.

답변

0

기본 클래스의 빈 createDeck 메서드와 두 하위 클래스의 메서드에 중단 점을 설정합니다.

내 생각에 IB (인터페이스 작성기)에서 탭 표시 줄 컨트롤러를 설정하면 탭 중 하나가 SetGameViewController 대신 일반 CardGameViewController의 인스턴스가됩니다.

+0

시도해 봤는데 사실 문제가있는 파일을 'PlayingCardGameViewController'로 변경했는데 여전히 작동하지 않습니다 – Itzik984

+0

객관적인 C를 처음 접했을 때 한 속성을 2 개 이상의보기에 연결할 수 있습니까? 속성 (두보기에 연결된 모든 속성)이 올바른 연결로 보일지라도 하나의보기 만 응답합니다. 어떻게 그렇게 될수 있니? – Itzik984

+0

용어 뷰와 뷰 컨트롤러를 계속해서 사용할 수 있습니다. 하지마. 보기 컨트롤러는보기가 아닙니다. 그들은 완전히 다릅니다. IBOutlet 속성을 둘 이상의보기에 연결할 수 있는지 묻고 있습니까? 내 대답은 아니오 야. –