简体   繁体   中英

Multiple NavigationControllers in one ViewController

I have a slideout menu created using SWRevealViewController. Each row of the slideout menu is connected to a NavigationController. I would that two row of two different TableViewController are connected to the same ViewController with a show segue.

这是我的故事板的一部分

When I navigate from the first NavigationController the ViewController work correctly and the description of the clicked cell is set in the navigation bar.

class Details: UIViewController {

var name:String = ""

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.title = name

    print(name)

}

Instead, when I navigate from the second NavigationController the ViewController doesn't work. The navigation bar is not shown, but the "name" parameter is printed.

Can anyone help me solve this problem?

Try this and see:

override func viewDidLoad() {
    super.viewDidLoad()

    print(name)
    self.navigationItem.title = name

    if let navController = self.navigationController {
      navController.isNavigationBarHidden = false
    } else {
      print("There is no Navigation Controller. You may not be showing this controller using 'navigation push'")
    }


 }

You can add in your code and put index no. and title of the cell:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{

    switch (indexPath.row)
    {
    case 2: name = "yourFirstNavigationTitleName"
        break
    case 3: name = "yourSecondNavigationTitleName"
        break
    default: break
    }

}

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