views:

286

answers:

0

I have a very complex game view with some custom views and some standard controls in the view. When some actions happen, i want to show a different view within the same area. What i have done is i have created two view objects in the view and incorporated the two views separately. As actions happen, i hide / unhide the views i need and it works good. For all of this i have a single View Controller on the main view and it works like a charm.

Now comes the problem: Now i wanted to add a third view similar to the two i have, but wanted to refactor the controller so that i have a different controller class for this view so as to keep my code a little legible - the controller is getting too large and Prama marks are too hard to follow!.

So i created a new UIViewController class (GameController2) along with an associated NIB file (GameController2.NIB). Now in my main view controller and NIB file, i created a small view item that i linked with an
IBOutlet UIView *gameAction

In My main controller file, i am creating an object of the new Controller2 class (controllerObject2) and am then loading the NIB file using
[[UIBundle mainbundle] loadNibNamed:@"GameController2" owner:controllerObject2 options:nil]];

Then i proceed to add the view of the controllerObject2 to the gameAction view using
[gameAction addSubview:controllerObject2.view];

I resize and hide the gameAction so that it is initialized and ready to go when i need it.
[gameAction sizeToFit];
gameAction.hidden = YES;

Then when i want to show the view, i unhide it using
gameAction.hidden = NO;

All this works perfectly fine but when i take any action on the controls that are defined in GameController2.NIB, they are not triggering the code in GameController2 class as expected. Actually the view is not taking any input. The buttons are not getting highlighted when clicking, the action outlets are not getting triggered. So I am effectively not able to hide the view anymore!

I am working strictly on the simulator currently.

What am i doing wrong? Am I not supposed to have multiple controllers for different parts of the view? That doesnt make sense, as i already have a tab bar controller and a navigation controller using table view work seemlessly. I even have a separate view controller loading another view properly from a NIB file int he Tab Bar controller.

I am adding other controllers (Navigation controllers) to the tab bar controller programatically even though the tab bar controller is created from the main NIB file and the navigation controllers are created programatically (No view to load).