   public let segmentControl = UISegmentedControl(frame: .zero)
 
   public func add(segmentTitle:String,viewController:UIViewController) -> Int{
-    let index = segmentControl.numberOfSegments - 1
+    let index = segmentControl.numberOfSegments
     segmentIndexViewControllerMap[index] = viewController
-    segmentControl.setTitle(segmentTitle, forSegmentAt:index)
+    segmentControl.insertSegment(withTitle: segmentTitle, at: index, animated: false)
     return index
   }
 

  }

  public func showSegmentTab(index:Int){
    var oldTabVC:UIViewController?
    if previousSelectedSegmentIndex > -1{
      oldTabVC = segmentIndexViewControllerMap[previousSelectedSegmentIndex]

    segmentControl.addTarget(self, action: #selector(onSelectedSegmentalChanged), for: .valueChanged)
    segmentControl.sizeToFit()
    navigationItem.titleView = segmentControl
    if segmentControl.numberOfSegments > 0 {
      showSegmentTab(index: 0)
    }
