3
votes

I have tab bar controller that show some items. And one item in tab bar controller have multiple view controller that show by a top tab bar. I already tried to make it with segment control and multiple container view but it didn't worked properly.

This is the storyboard that I want to make StoryboardExample

I want the three view controllers in the right show in View Controller 2 in item tab bar and control by the top tab bar. So, its like Activity Tab in Youtube Application that have top tab bar with item Shared and Notifications. Shared View in Youtube Application , Notification View in Youtube Application

Edit

This is the code to change the view from segment control,

@objc func changeGroup(sender: UISegmentedControl)
{
    if sender.numberOfSegments == 3
    {
        switch sender.selectedSegmentIndex
        {
        case 0 :
            if self.groupView.isHidden == true
            {
                self.groupView.isHidden = false
            }
            if self.inspirationView.isHidden == false
            {
                self.inspirationView.isHidden = true
            }
            if self.pesantrenView.isHidden == false
            {
                self.pesantrenView.isHidden = true
            }

        case 1:
            if self.groupView.isHidden == false
            {
                self.groupView.isHidden = true
            }
            if self.inspirationView.isHidden == true
            {
                self.inspirationView.isHidden = false
            }
            if self.pesantrenView.isHidden == false
            {
                self.pesantrenView.isHidden = true
            }

        case 2:
            if self.groupView.isHidden == false
            {
                self.groupView.isHidden = true
            }
            if self.inspirationView.isHidden == false
            {
                self.inspirationView.isHidden = true
            }
            if self.pesantrenView.isHidden == true
            {
                self.pesantrenView.isHidden = false
            }

        default :
            break
        }
    }
}
1
post some of your code , what you have done so farTejas Pandya
I already tried to make it with segment control and multiple container view but it didn't worked properly. What didn't work for you ?Prashant Tukadiya
@Tej Hai tej, that is the method that I use to switch the container view in that item tabMuhammad Syahroyni
@PrashantTukadiyaThe tableview delegate and datasource in the container view controller didn't work properly. Sometimes the data show, sometimes not.Muhammad Syahroyni

1 Answers

0
votes

What you want is a custom tab bar controller. Follow this lead and you'll be home: https://github.com/codepath/ios_guides/wiki/Creating-a-Custom-Tab-Bar

here you should know, they create the tab bar manually with a UIView and Buttons I have implemented a basic version with a native tab bar here: https://github.com/zameerascentic/customTabBarNative

You should note (differs from that tutorial):

  1. Tab bar is positioned bottom here, you can move anywhere you want
  2. View controllers are created seperately and loaded into a UIView called ContainerView on tab bar item select delegate
  3. Check the tab bar tags, it will be 0,1 etc, because it will be the indexes of the viewControllers array - all our view controllers are loaded into an array for easy reference.
  4. ViewControllers are given storyboardIDs to be called by tab bar