2017-11-13 9 views
1

5 개의 항목이있는 TabBarController가 있습니다. 다른 항목에서이 탭보기를 재사용하여 일부 항목을 제거해야합니다. 어떻게해야합니까? 프로그래밍 방식으로이를 수행하기위한 isEnabled 버튼 만 있습니다. 하지만 탭 항목을 숨겨야합니다.iOS : 이전 컨트롤러의 일부 탭을 제거하고 TabBarController를 다시 사용하십시오.

사례 1 : 목적 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

의 다른 섹션에있는 탭 중 일부만 표시 : 스토리 보드

@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에서 모든 탭 항목을 표시해야 단일 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]; 
} 

나는 또한 그것을 신속를 사용하고 있지만, 지금 내가 신속한없는 확장 클래스의 인스턴스를 생성 코드 ...