0

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
}

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

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

and the second one:

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 also have tab bar navigator to switch between the 2 views.

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

Meaning the createDeck function is never called,

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

What i have tried:

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.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
Itzik984
  • 15,968
  • 28
  • 69
  • 107

1 Answers1

0

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

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.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Tried this as well... in fact i changed the problematic file to be ׳PlayingCardGameViewController׳ as well, and it still not working – Itzik984 Jan 08 '14 at 17:55
  • i new to objective c, is it possible to connect one property into 2 views or more? even though the property (any one which is connected to both views) seems OK connection wise, only one view responds to it. how can that be? – Itzik984 Jan 08 '14 at 18:01
  • You keep using the term view and view controller interchangeably. Don't. A view controller is not a view. They are totally different. Are you asking if it's possible to connect an IBOutlet property to more than one view? The answer is no. – Duncan C Jan 08 '14 at 18:49
  • That is probably what is happening, the code looks sound. In the storyboard you may not be referencing the right controller. You could put an NSLog in CardGameViewController createDeck to see if it is being called since it should not be. – 0xFADE Jan 08 '14 at 20:05