iOS NavigationController问题处理

  • 隐藏返回按钮
    ViewController.navigationItem.hidesBackButton = true

  • 隐藏返回按钮文字
    navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.plain, target: nil, action: nil)

  • 如果使用上面的方法依然有返回文字,把上面的代码放进viewWillAppear方法中。

  • 导航栏标题不见了
    如果确认已经在控制器中设置了title,并且NavigationBar也可见,但是还是看不到标题。试试下面的代码:
    navigationBar.isTranslucent = false

  • 在导航控制器中临时插入控制器

    var controllers = navigationController!.viewControllers
    controllers.insert(newController, at: controllers.index(of: index)!)
    navigationController?.viewControllers = controllers
    
  • 替换根控制器

     var viewControllers = navigationController?.viewControllers
     viewControllers?.removeAll()
     viewControllers?.append(self)
     if let childControllers = viewControllers {
          navigationController?.viewControllers = childControllers
      }
    
  • 移除特定的控制器

    var viewControllers = navigationController?.viewControllers
    viewControllers?.remove(at: index)
    navigationController?.viewControllers = viewControllers
    

你可能感兴趣的:(iOS NavigationController问题处理)