我正在尝试创建一个通用视图控制器和两个其他视图,它们都将从中继承。
现在这是通用视图(我认为是相关的 - 如果需要其他内容,我会添加它):
@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
我也有标签栏导航器在 2 个视图之间切换。
问题是,无论我做什么,第一个(SetGameViewController)都不会被实例化,
意味着该createDeck
函数永远不会被调用,
而第二个(PlayingCardGameViewController)每次都可以。
我试过的:
- (CardMatchingGame*)game
在主视图功能上放置断点。
只有当我尝试启动第二个工作视图时才会调用这个,而不是坏的。
如果有什么遗漏可以提供一定的线索,请告诉我,我会添加它。