【发布时间】:2014-01-26 23:17:29
【问题描述】:
我正在尝试创建一个通用视图控制器和两个其他视图,它们都将继承自。
现在这是通用视图(我认为是相关的 - 如果需要其他内容,我会添加它):
@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
我还有标签栏导航器可以在两个视图之间切换。
问题是,无论我做什么,第一个 (SetGameViewController) 都不会实例化,
意味着永远不会调用createDeck 函数,
虽然第二个(PlayingCardGameViewController)每次都可以。
我尝试过的:
在主视图- (CardMatchingGame*)game 函数上放置断点。
只有当我尝试启动第二个工作视图时才会调用这个,而不是坏的。
如果有什么不足的地方,请告诉我,我会补充的。
【问题讨论】:
标签: ios objective-c inheritance uiviewcontroller cs193p