嘿,在 appDelegate 中创建 tabBarController 的属性并在那里分配所有 ViewController,然后从 yourViewController 调用 tabBarController
在 AppDelegate.h
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (retain, nonatomic) IBOutlet UITabBarController *tabBarController;
在 AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self makeTabBar];
[self addInitialVIew];
[self.window makeKeyAndVisible];
return YES;
}
-(void)makeTabBar
{
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstViewController *firstVC =[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
firstNC.tabBarItem.title=@"Profile";
firstVC.tabBarController.tabBar.tag = 0;
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UINavigationController *SecondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];
SecondNavController.tabBarItem.title = @"Search";
secondVC.tabBarController.tabBar.tag = 1;
NSArray *viewControllers =[[NSArray alloc]initWithObjects:firstNC,SecondNavController, nil];
[tabBarController setViewControllers:viewControllers animated:NO];
}
-(void) addInitialVIew
{
InitialViewController *initialViewController = [[InitialViewController alloc]initWithNibName:@"InitialViewController" bundle:nil];
navigationController = [[UINavigationController alloc]initWithRootViewController:ViewController];
[self.window addSubview:navigationController.view];
}
现在InitialViewController
您可以添加 yourTabBar 并删除InitialViewController
- (IBAction)switchToTabBarBtnPress:(id)sender
{
AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];
[[[appdelegte navigationController] view]removeFromSuperview];
[[appdelegte window]addSubview:[[appdelegte tabBarController]view]];
[[appdelegte tabBarController]setSelectedIndex:0];
}
并按照我的回答
回答