如何从Appdelegate导航到另一个视图(tabview)。 我试过这个
MyViewController *mvc = [[MyViewController alloc] init];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:mvc] autorelease];
self.window.rootViewController = navController;
导航到MyViewController,但是隐藏了标签栏,在该视图中后退按钮也不起作用(popView)
我正在导航到一个不是tabviewcontroller的视图(只隐藏标签栏)
答案 0 :(得分: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;
}
答案 1 :(得分: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;
}