0

我有一个 UITabBarController 和 UINavigationController。它是 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; 
}

在课堂上有一个带有代码的登录按钮:

- (IBAction)buttonLogin:(id)sender
{
    DashVC * dashBoard = [[DashVC alloc] initWithNibName:@"DashVC" bundle:nil];
    [self.navigationController pushViewController:dashBoard animated:YES];
}

我点击按钮你不能做推视图 DashVC。谁能解释我做错了什么?我调试,不输入方法:

  - (void)viewDidLoad

dashVC 类。

4

2 回答 2

3

像这样更改您的代码:

- (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;
}

您需要UINavigationController在您的内部添加一个LoginViewController

于 2013-10-09T14:49:37.907 回答
1
- (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;
}
于 2013-10-09T14:56:10.503 回答