簡體   English   中英

從Appdelegate導航到選項卡視圖

[英]Navigation from Appdelegate to tab view

如何從Appdelegate導航到另一個視圖(一個tabview)。 我已經試過了

  MyViewController *mvc = [[MyViewController alloc] init];
  UINavigationController *navController = [[[UINavigationController alloc]  initWithRootViewController:mvc] autorelease];
   self.window.rootViewController = navController;

它導航到MyViewController,但選項卡欄被隱藏,該視圖中的向后按鈕也不起作用(popView)

我導航到不是tabviewcontroller的視圖(僅隱藏了選項卡欄)

試試這個創建標簽欄

tabBar_Controller = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray =[[NSMutableArray alloc]initWithCapacity:2];


firstViewController = [[FirstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:firstViewController];
nav.tabBarItem.title = @"item1";
nav.navigationBar.barStyle = UIBarStyleBlack;
[localControllersArray addObject:nav];
[self setNav:nil];

secondViewController = [[SecondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
nav = [[UINavigationController alloc]initWithRootViewController:secondViewController];
nav.tabBarItem.title = @"item2";
[localControllersArray addObject:nav];
[self setNav:nil];

tabBar_Controller.viewControllers = localControllersArray;
tabBar_Controller.delegate = self;
tabBar_Controller.selectedIndex = 0;

 self.window.rootViewController = tabBar_Controller;

您也可以在Appdelegate嘗試使用This。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[[SPHFirstViewController alloc] initWithNibName:@"SPHFirstViewController" bundle:nil] autorelease];
    UIViewController *viewController2 = [[[SPHSecondViewController alloc]  initWithNibName:@"SPHSecondViewController" bundle:nil] autorelease];
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = @[viewController1, viewController2];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

    UINavigationController *navigation;

}

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;

//主文件

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;

@synthesize viewController = _viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

    navigation = [[UINavigationController alloc] initWithRootViewController:self.viewController];

   self.window.rootViewController = navigation;

    [self.window makeKeyAndVisible];

   return YES;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM