嘿讓你tabBarController在的appDelegate屬性,並指定所有的ViewController有再打電話給你tabBarController從yourViewController
在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];
[email protected]"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];
}
,並按照我的回答
Answer
誰是'自我'在這裏? –
是你的問題解決? – Rajneesh071