Reputation: 97
I have a UITabBarController and UINavigationController. the code it is AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_tabBarAppDelegate = [[UITabBarController alloc] init];
LoginVC *loginViewController = [[LoginVC alloc]initWithNibName:@"LoginViewController" bundle:nil];
[_tabBarAppDelegate setViewControllers:@[loginViewController]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController: _tabBarAppDelegate];
// [self hideTabBar:self.tabBarAppDelegate];
[self.window makeKeyAndVisible];
return YES;
}
In class have a login button with the code:
- (IBAction)buttonLogin:(id)sender
{
DashVC * dashBoard = [[DashVC alloc] initWithNibName:@"DashVC" bundle:nil];
[self.navigationController pushViewController:dashBoard animated:YES];
}
I click on the button you can not do push the view DashVC. Would anyone can explain what I'm doing wrong? I debug and do not enter the method:
- (void)viewDidLoad
the class dashVC.
Upvotes: 0
Views: 306
Reputation: 566
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Upvotes: 1
Reputation: 8247
Change your code like this :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_tabBarAppDelegate = [[UITabBarController alloc] init];
LoginVC *loginViewController = [[LoginVC alloc]initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[_tabBarAppDelegate setViewControllers:@[navigationController]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController: _tabBarAppDelegate];
// [self hideTabBar:self.tabBarAppDelegate];
[self.window makeKeyAndVisible];
return YES;
}
You need to add a UINavigationController
inside your LoginViewController
Upvotes: 3