1

I have already read this LINK , but not working for me. I want to show a viewController as a subview in another viewController.

Here is my code -

import UIKit
import CarbonKit

class ViewController: UIViewController, CarbonTabSwipeNavigationDelegate {

 @IBOutlet weak var containerView: UIView!

 override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let items = ["All",  "WOMEN",  "MEN",  "KIDS",  "HOME",  "CITY"]
        let carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: items, delegate: self)
        carbonTabSwipeNavigation.insert(intoRootViewController: self)
    }

    func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {

        //           let screen = self.storyboard?.instantiateViewController(withIdentifier: "demo") as! demo
        //           showSubViewContrller(subViewController: vc)
        //           return screen

        let storyBoard = getStoryBoardByIndentifier(identifier: "All")
        let vc = storyBoard.instantiateViewController(withIdentifier: "AllViewController") as! AllViewController
        showSubViewContrller(subViewController: vc)
        return vc
    }

    //Subview Controller
    func showSubViewContrller(subViewController:UIViewController) {
        self.addChildViewController(subViewController)
        subViewController.view.frame = containerView.frame
        self.containerView.addSubview(subViewController.view)
        subViewController.didMove(toParentViewController: self)
    }

    func getStoryBoardByIndentifier(identifier:String)->UIStoryboard {
        return  UIStoryboard.init(name: identifier, bundle: nil)
    }

}

I have a NavigationBar and a tapBar. Would like to show the viewController inside the view in a container.

enter image description here

But when the view loads it's coverUp/hide the tabBar.

enter image description here enter image description here

How to solve this and show the viewController in my specified container. Project Link - GitHub

Malik
  • 3,763
  • 1
  • 22
  • 35
Rashed
  • 2,349
  • 11
  • 26

1 Answers1

2

Somehow i am able to fix your issue with below changes:

Replace this method carbonTabSwipeNavigation.insert(intoRootViewController: self) with carbonTabSwipeNavigation.insert(intoRootViewController: self, andTargetView: containerView) in viewDidLoad

Note : Give UITaBar bottom constraint to SuperView not SafeArea:

enter image description here

Add below code in ViewController:

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        tabbar.invalidateIntrinsicContentSize()
    }

After doing this when you run you will UITabBar:

enter image description here

Paulw11
  • 108,386
  • 14
  • 159
  • 186
iVarun
  • 6,496
  • 2
  • 26
  • 34
  • @MdRashedPervez Worked for you? – iVarun Sep 13 '18 at 10:30
  • thank you very much for your kind help. It works for me :) . But another problem occurs - when the tabBar view appears on the container the segment header is gone . Could u help me on this. :) – Rashed Sep 13 '18 at 10:46
  • 1
    I have checked Tabbar is not causing issue. Look like there is problem with `carbonTabSwipeNavigation.insert(intoRootViewController: self, andTargetView: containerView)` – iVarun Sep 13 '18 at 11:27