2017-11-13 4 views
1

5つのアイテムを持つTabBarControllerがあります。私はいくつかの項目を削除して別の場所でこのタブビューを再利用する必要があります。どうやってやるの。プログラムでそれを行うためのisEnabledボタンしかありません。しかし、私はタブ項目を非表示にする必要があります。iOS:古いコントローラのいくつかのタブを削除してTabBarControllerを再利用する

ケース1:ストーリーボード

からすべてのタブ項目を表示する必要が
@IBAction func partialAction(_ sender: UIButton) { 
    let partialTabController = storyboard?.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController 
    partialTabController.selectedViewController = partialTabController.viewControllers?[3] 

    present(partialTabController,animated: true,completion: nil) 

} 

ケース2:Objective Cの 用アプリケーション

@IBAction func partialAction(_ sender: UIButton) { 
    let partialTabController = storyboard?.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController 
    partialTabController.selectedViewController = partialTabController.viewControllers?[3] 

    // Can I remove some of the tab item using code here 

    present(partialTabController,animated: true,completion: nil) 

} 
+0

こんにちは@Krishnakumar CNは、既存のコードのスニペットを追加すると助けになります。 –

答えて

0

の別のセクションでは、タブのほんの数を表示します単一のTabBarControllerで別の画面に異なるタブバーを設定する場合... UITabBarControllerの拡張クラスを作成し、カスタム関数バーを作成します。

-(void)customTabBar { 
[self.tabBar setBackgroundColor:[UIColor whiteColor]]; //[CommonFunctions colorWithRed:255.0 green:240.0 blue:237.0 alpha:1.0]]; 
[self.tabBar setBackgroundImage:[[UIImage alloc]init]]; 
UITabBar *tabBar = self.tabBar; 
UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 
UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; 
UITabBarItem *item3 = [tabBar.items objectAtIndex:3]; 
UITabBarItem *item4 = [tabBar.items objectAtIndex:4]; 

[item0 setTitle:@"Home"]; 
[item0 setImage:[[UIImage imageNamed:@"Home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item0 setSelectedImage:[[UIImage imageNamed:@"Homeblue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

[item1 setTitle:@"Browse"]; 
[item1 setImage:[[UIImage imageNamed:@"Browse"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item1 setSelectedImage:[[UIImage imageNamed:@"Browseblue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

[item2 setTitle:@"Post"]; 
[item2 setImage:[[UIImage imageNamed:@"Post"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item2 setSelectedImage:[[UIImage imageNamed:@"Postblue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item3 setTitle:@"Activity"]; 
[item3 setImage:[[UIImage imageNamed:@"Activity"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item3 setSelectedImage:[[UIImage imageNamed:@"Activityblue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item4 setTitle:@"Profile"]; 
[item4 setImage:[[UIImage imageNamed:@"Profile"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[item4 setSelectedImage:[[UIImage imageNamed:@"Profileblue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 


[item0 setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)]; 
[item1 setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)]; 
[item2 setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)]; 
[item3 setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)]; 
[item4 setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)]; 

}

今、あなたは、クラスのインスタンスを作成し、タブあなたに従ってを使用し....

をそしてappdelegateであなたのクラスのインスタンスを作成し

に応じてタブを追加する機能を作成することができます

実際に私はまた、迅速にそれを使用していますが、今の私は迅速持っていない拡張クラスのために

@property (strong, nonatomic) CustomTabBarViewController *tabBarController; 


    -(void)createTabBarContoller 
{ 
    //Created all tabs controller to be the default for tabs 
    UIViewController *viewController1 = [[HomeViewController alloc] 
    initWithNibName:@"HomeViewController" bundle:nil]; 
    UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1]; 

    UIViewController *viewController2 = [[SaleViewController alloc] initWithNibName:@"SaleViewController" bundle:nil]; 
    UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2]; 

    UIViewController *viewController3 = [[SellCameraViewController alloc] initWithNibName:@"SellCameraViewController" bundle:nil]; 
    UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3]; 

    UIViewController *viewController4 = [[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil]; 
    UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:viewController4]; 

    UIViewController *viewController5 = [[MeViewController alloc] initWithNibName:@"MeViewController" bundle:nil]; 
    UINavigationController *navController5 = [[UINavigationController alloc] initWithRootViewController:viewController5]; 

    self.tabBarController = [[CustomTabBarViewController alloc] init]; 
    self.tabBarController.viewControllers = @[navController1, navController2, navController3, navController4, navController5]; 

    [self.tabBarController setDelegate:self]; 
    [self.tabBarController customTabBar]; 
    self.tabBarController.tabBar.layer.borderWidth = 0.50; 
    self.tabBarController.tabBar.layer.borderColor = [UIColor colorWithRed:236.0/255.0 green:236.0/255.0 blue:236.0/255.0 alpha:1].CGColor; 
    self.tabBarController.tabBar.clipsToBounds = true; 

    [self.window setRootViewController:self.tabBarController]; 
} 

をインスタンスを作成します。コード...

関連する問題