在视图控制器目标c上的继承 [英] Inheritance on view controller Objective c

查看:69
本文介绍了在视图控制器目标c上的继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个通用的视图控制器和两个其他视图,这两个视图都将继承自该视图.

I am trying to create a generic view controller and 2 other views which both will inherit from.

现在这是通用视图(我认为是相关的-如果需要其他内容,我将其添加):

Now this is the generic view (what i think is relevant - if something else is needed i will add it):

@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
}

这是继承上述文件的2个文件:

and these are the 2 files which inherit the mentioned file:

SetGameViewController.h:

SetGameViewController.h:

#import "CardGameViewController.h"

@interface SetGameViewController : CardGameViewController

@end

SetGameViewController.m:

SetGameViewController.m:

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

@interface SetGameViewController ()

@end

@implementation SetGameViewController

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

@end

和第二个:

PlayingCardGameViewController.h:

PlayingCardGameViewController.h:

#import "CardGameViewController.h"

@interface PlayingCardGameViewController : CardGameViewController

@end

PlayingCardGameViewController.m:

PlayingCardGameViewController.m:

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

@interface PlayingCardGameViewController ()

@end

@implementation PlayingCardGameViewController

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

我还有一个标签栏导航器,可以在两个视图之间切换.

I also have tab bar navigator to switch between the 2 views.

问题是,无论我做什么,第一个(SetGameViewController)都不会实例化,

The thing is, the first (SetGameViewController) is never instantiated no matter what i do,

从不调用createDeck函数,

第二次(PlayingCardGameViewController)每次都可以.

While the second one (PlayingCardGameViewController) is ok every time.

我尝试过的事情:

在主视图- (CardMatchingGame*)game函数上放置断点.

placing break points on the main view - (CardMatchingGame*)game function.

只有在我尝试启动第二个工作视图时才调用此视图,而不是坏视图.

this one only gets called when i am trying to start the second working view, and not the bad one.

如果缺少任何线索,请告诉我,我会添加.

If there is anything missing to give a certain lead, please let me know and i will add it.

推荐答案

在基类的空createDeck方法以及两个子类的方法中设置断点.

Set breakpoints on the empty createDeck method in the base class, as well as on the method in your two subclasses.

我的猜测是,当您在IB(界面生成器)中设置选项卡栏控制器时,您将其中一个选项卡设置为通用CardGameViewController的实例,而不是SetGameViewController.

My guess is that when you set up your tab bar controller in IB (Interface Builder) , you made one of the tabs be an instance of the generic CardGameViewController instead of a SetGameViewController.

这篇关于在视图控制器目标c上的继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆