简体   繁体   中英

How to navigate to TabBar ViewController on click of button on popover ViewController in swift?

I have TabBarController project, with navigation bar. On navigation bar I have popover on right BarButtonItem . On that popover ViewController I have one button. On that button click I want to move to any TabBarController .

I tried with

tababarController.selectedIndex = 1

But view is not switching

Is there any solution?

您将关闭popover并从主视图控制器中的popover viewcontroller中调用委托方法,然后在委托方法中设置工具栏的选定索引。

setSelectedIndex should work right.

Maybe you are not getting correct reference of your UITabBarController and while checking, you might get it nil.

class PopupviewController {

weak var delegate: NavigateViewDelegate?

func buttonPress () {
   delegate?.navigate()
 }  
}
protocol NavigateViewDelegate : class {
      func navigate()
}
class TabBarViewController :NavigateViewDelegate {

  func navigate() {
    tababarController.selectedIndex = 1   
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM