UIViewController *newView = [[UIViewController alloc] initWithNibName:@"NewView" bundle:[NSBundle mainBundle]];
tabBarController.selectedViewController = newView;
Why doesn't this work?
UIViewController *newView = [[UIViewController alloc] initWithNibName:@"NewView" bundle:[NSBundle mainBundle]];
tabBarController.selectedViewController = newView;
Why doesn't this work?
The selectedViewController property of a UITabBarController must be one of the tab bar's existing tabs (as defined in its viewControllers property). You may want to either push the new controller onto an existing tab (which would have to be a UINavigationController), or add the viewController to the viewControllers array.
Because that view controller isn't part of the UITabBarController
.
If you look at the Apple reference for the selectedViewController
property, you'd see:
The specified view controller must be in the
viewControllers
array.
You need to add the view controller to UITabBarController
, using the viewControllers
property, so the view controller has a tab, so you can then select that view controller's tab.