Okay ... this seems absurd, but I answer: P
I managed to get it working (finaly!), And I found that I was controlling viewControllers using the BAAAAD method, so I changed the code in the coordination controller:
Firstly, I have no "real" mainViewController with NIB and stuf no more ...
OLD initialize
- (void) initialize{ C6Log(@""); [self checkDevice]; _mainVC = [C6MainViewController initWithDevice:device]; _activeVC = _mainVC; [self checkLanguage]; [self chooseFirstView]; }
NEW initialize
- (void) initialize{ C6Log(@""); [self checkDevice]; [self checkLanguage]; [self chooseFirstView]; }
checkDevice checks if it is an iPhone or iPad, so I can choose the right NIB.
checkLanguage checks [NSUserDefaults standardUserDefaults] for the language
Finally, I call selectFirstView:
OLD selectFirstView
-(void) chooseFirstView{ // If a language was not setted, go to language settings view if (!language) { C6Log(@"Going to Language Settings"); C6LanguageSettingsViewController *languageVC = [C6LanguageSettingsViewController initWithDevice:device]; [_mainVC.view addSubview:languageVC.view]; } else { C6Log(@"Going to User Settings", language); C6AccountSettingsViewController *accountVC = [C6AccountSettingsViewController initWithDevice:device]; [_mainVC.view addSubview:accountVC.view]; } }
NEW selectFirstView
-(void) chooseFirstView{ // If a language was not setted, go to language settings view _activeVC = [[UIViewController alloc] init]; UIImage *bgImage = [UIImage imageNamed:@"bg.png"]; UIImageView *bgView = [[UIImageView alloc] initWithImage:bgImage]; [_activeVC.view addSubview:bgView]; if (!language) { C6Log(@"Going to Language Settings"); languageVC = [C6LanguageSettingsViewController initWithDevice:device]; [_activeVC.view addSubview:languageVC.view]; } else { C6Log(@"Going to User Settings", language); accountVC = [C6AccountSettingsViewController initWithDevice:device]; [_activeVC.view addSubview:accountVC.view]; } }
The big change is WHEN and HOW I initiated _activeVC ... And the fact that both _languageVC and _accountVC are now global variables.
Well, after this change, the NIB button calls both IBAction methods: this is the file owner and coordination controller.
Another BIG thing about using this type of template is switching from one view to another without exploding the iOS deviceβs memory ... here's how I do it inside the coordination controller:
- (IBAction) requestViewChangeByObject:(id)object { int buttonTag = [object tag]; // dividend int viewTag = buttonTag / divisor; // quotient int actionTag = buttonTag - (divisor * viewTag); // remainder C6Log(@"ViewTag: %d", viewTag); switch (viewTag) { case LanguageTags:{ C6Log(@"LanguageTags - button %d", actionTag); accountVC = [C6AccountSettingsViewController initWithDevice:device]; UIView *fromView = languageVC.view; UIView *toView = accountVC.view; [self switchFrom:fromView To:toView usingAnimation:AnimationPushFromRigh]; } break; case AccountTags:{ C6Log(@"AccountTags - button %d", actionTag); switch (actionTag) { case 0:{ C6Log(@"Go back"); languageVC = [C6LanguageSettingsViewController initWithDevice:device]; UIView *fromView = accountVC.view; UIView *toView = languageVC.view; [self switchFrom:fromView To:toView usingAnimation:AnimationPushFromLeft]; } break; default: break; } } break; default: break; } }
At the beginning of the method, I do a lot of mathematics ... I "created" a template in which each NIB should have its tags starting at 100 times ... so that the language starts at 0, the score is from 100 ........ .
#define divisor 100 #define LanguageTags 0 #define AccountTags 1
Then it changes the view that I pass from one view to another:
-(void) switchFrom:(UIView*) fromView To:(UIView*) toView usingAnimation:(int) animation{ C6Log(@"");
I really hope this helps those trying to use this focal point pattern: P