Reputation: 1
I've been struggling over this for a while, sifting through solutions online but haven't managed to get there so I figured it was about time to ask you wonderful folk. I have a tab bar application in which I am trying to use a navigation controller containing a table view (TableViewController
) to switch to different views depending on the cell that is pressed.
When touching a cell in the table view my SecondViewController
is loaded (this is working as I checked by colouring the background in the viewDidLoad()
method) however the interface (XIB
) is not loading and thus the window is blank (or coloured in the case of my background test). The window (SecondViewController
) is supposed to contain a UIScrollerView
which works when accessing the view directly. I should mention that all the view controllers are contained within a single XIB
file and the XIB
file contains the tab bar controller and a blank window required by the App Delegate (window and tabBarController
).
This is how I switch views from TableViewController.m
(rootViewController
of navigationController
)
SecondViewController *viewSecond = [SecondViewController alloc];
self.secondViewController = viewSecond;
[self.navigationController pushViewController:self.secondViewController animated:YES];
This is the applicationDidFinishLaunchingWithOptions()
in appDelegate.m
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
tabBarController.moreNavigationController.navigationBar.hidden = YES;
return YES;
This was actually a follow on from an old project so I'm now sure why the blank window is required in the XIB
(if that has anything to do with the problem) as it is not required in the template tab bar application. I've only just started iOS development so I apologize if I'm vague anywhere. Any help would be deeply appreciated.
Upvotes: 0
Views: 863
Reputation: 1294
In your TableViewController.m
, you have missed to init
your SecondViewController
. Just calling alloc
doesn't load from nib.
So change
SecondViewController *viewSecond = [SecondViewController alloc];
into SecondViewController *viewSecond = [[SecondViewController alloc] init];
or SecondViewController *viewSecond = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
Upvotes: 2