【问题标题】:Change back button place from left bar button to right Bar button with reverse animation使用反向动画将后退按钮位置从左栏按钮更改为右栏按钮
【发布时间】:2016-12-20 06:07:43
【问题描述】:

如何将返回按钮位置更改为嵌入式导航的右栏按钮并将图标从<更改为>

【问题讨论】:

    标签: ios swift uinavigationcontroller uibarbuttonitem back-button


    【解决方案1】:

    我的建议是:

    • 隐藏后退按钮:

      navigationItem.hidesBackButton = YES
      
    • 添加一个带有图像箭头的右键:

      let backButton = UIBarButtonItem(title: ">", style: .Plain, target: self, action: #selector(backTapped))
      navigationItem.rightBarButtonItem = backButton
      

    backTapped 的动作会将视图控制器从导航控制器堆栈中弹出。

    如果这种方法可以解决您的问题,请在 cmets 中告诉我。

    【讨论】:

    • 感谢您的回答。我这样做但是有一个小问题。当我回到上一个视图时,然后在上面显示后退按钮,我不想显示它!
    • 我使用: let newView = sabtEnsheabViewController(nibName: "sabtEnsheabViewController", bundle: nil) self.navigationController?.pushViewController(newView, animated: false) 但它显示返回按钮到另一个视图使用这个: let newView = EnsheabSabteNamViewController(nibName: "EnsheabSabteNamViewController", bundle: nil) self.presentViewController(newView, animated: false, completion: nil) 它不再显示导航栏
    • @AliSHelcid 你需要在每个你想要这种行为的控制器中编写这段代码,在 viewdidload 中尝试
    • 感谢您的回答,我这样做了。这不是一个最好的解决方案,但却是一个。
    【解决方案2】:

    我用:

    让 newView = sabtEnsheabViewController(nibName: "sabtEnsheabViewController", bundle: nil)

    self.navigationController?.pushViewController(newView, animated: false)

    但它显示返回按钮到另一个视图

    使用这个:

    让 newView = EnsheabSabteNamViewController(nibName: "EnsheabSabteNamViewController", bundle: nil)

    self.presentViewController(newView, animated: false, completion: nil)

    它不再显示导航栏

    【讨论】:

      【解决方案3】:
       I use this way for change back button position.
      
         //put this code in viewDidLoad()
      
      
         navigationItem.hidesBackButton = true
         navigationItem.rightBarButtonItem = UIBarButtonItem(title: " > ", style: .done,target: self, action: #selector(addTapped))
      
      
         //function to handle back navigation
      
         @objc func addTapped(){
      
          navigationController?.popToRootViewController(animated: true)
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多