I am trying to make a button on a navigation controller that causes a transition to another view controller (that has a back button to the previous nav view). I'm trying to do this programmatically. I made a UINavigationController and a UITabBarController. The nav controller is the opening tab of the tab controller. I made a subclass of the UIViewController called SubVieController. I haven't added anything to the Sub classes, only the auto generated material. I've made all my edits to the didFInishLaunchingWithOptions method in Appdelegate.m.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SubViewController * firstTab= [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
SecondViewController *secondTab = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
SubTableController *table = [[SubTableController alloc]initWithNibName:@"SubTableController" bundle:nil];
navigationController1.tabBarItem.title = @"First Nav";
secondTab.tabBarItem.title =@"Second";
table.title = @"Third Table";
tabBarController.viewControllers = @[navigationController1,secondTab, table];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
And I try to move a Button onto the SubViewController.xib file to connect it into the code so I can make a button action. But when I ctrl+drag, nothing inserts into the code like usual.
What do I do to have the button cause a transition from the starting view to a separate view that is still considered to be on the 1st tab, with a back button to the first view which is also in the first tab?
EDIT: This code seems to work for the button action: - (IBAction)transition:(UIButton *)sender{ SubViewController * view2 = [[SubViewController alloc]init]; [self.navigationController pushViewController:view2 animated:YES]; }
