0

如何从 Appdelegate 导航到另一个视图(tabview)。我试过这个

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

它导航到 MyViewController,但标签栏被隐藏,后退按钮在该视图中也不起作用(popView)

我正在导航到不是 tabviewcontroller 的视图(仅隐藏标签栏)

4

2 回答 2

0
#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;

}
于 2013-01-08T07:12:01.363 回答
0

试试这个来创建标签栏

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.

- (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;
}
于 2013-01-08T06:57:50.220 回答