在iOS 11.2.2上隐藏后退按钮

时间:2018-01-09 18:16:31

标签: ios swift uinavigationbar

我正试图隐藏导航栏的后退按钮。 我可以在早于iOS 11.2.2的所有iOS版本中执行此操作

我已经尝试过以下代码:

 self.navigationController?.navigationItem.setHidesBackButton(true, animated: true)
 self.navigationController?.navigationItem.hidesBackButton = true
 self.navigationItem.setHidesBackButton(true, animated: true)
 self.navigationItem.hidesBackButton = true

似乎在iOS 11.2.2中没有任何效果

我正在使用Xcode 9和Swift 4

4 个答案:

答案 0 :(得分:4)

我正在使用Xcode9,Swift 4& iOS 11.2和

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Text pasted to left column goes to right column</title>
</head>
<body>
  <h3>With Google Chrome, Version 63.0.3239.132 (Official Build) (64-bit) under
    Windows Pro 7 64 bit,
    clicking and pasting in either column pastes to the right column.
   </h3>
  
    <div id=leftColumn class="myColumn frame">
        <p id=leftPara style="word-wrap: break-word; white-space: pre-wrap;" class=clickable></p>
    </div>
    <div id=rightColumn class="myColumn frame">
        <p id=rightPara style="word-wrap: break-word; white-space: pre-wrap;" class=clickable></p>
    </div>
</body>

完全正常。

答案 1 :(得分:3)

Swift 4 Xcode 9.2

建议我从A控制器移动到B控制器,然后在A之前嵌入导航控制器。在控制器B中,我编写此代码并且工作正常。

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
         self.navigationItem.setHidesBackButton(true, animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

答案 2 :(得分:3)

它为我工作。

override func prepare(for segue: UIStoryboardSegue, sender: Any?){
  if segue.identifier == "viewcontroller"{
    let objVC = segue.destination as? viewcontroller
    objVC?.navigationItem.hidesBackButton = true
  }
}

答案 3 :(得分:0)

您在出现之前设置hidesBackButton属性,或者按下后退按钮视图控制器。

@objc func showHidedBackButtonViewController() {
    navigationItem.hidesBackButton = true
    let hidedBackButtonViewController = HidedBackButtonViewController()
    navigationController?.pushViewController(hidedBackButtonViewController, animated: true)
}