【问题标题】:My show segue not using NavigationController我的节目不使用 NavigationController
【发布时间】:2017-03-29 19:54:55
【问题描述】:

我在使用导航控制器连接到我的详细视图时遇到问题。

我正在使用表格视图来显示一些练习,当您单击练习时,您将进入详细视图,嵌入在导航控制器中 我删除了 Tableview,并添加了 3 个按钮,每个按钮都有自己的“显示”segue 到详细视图。它几乎可以工作,但它现在不使用我的导航控制器,这意味着视图只是呈现有点像模态演示。 我已经尝试在一个按钮上删除 segue 并替换为此操作:

@IBAction func strengthButton(_ sender: UIButton) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let destination = storyboard.instantiateViewController(withIdentifier: "ExerciseViewController") as! ExerciseViewController
    destination.componentaccessid = -1;
    destination.openedFromUrl = false;
    destination.exercise = self.strengthexercise
    destination.exercisetype = .strength
    self.navigationController?.present(destination, animated: true, completion: nil)
}

但这完全一样。

我有一个准备函数:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let identifier = segue.identifier,
        let destination = segue.destination as? ExerciseViewController{
        destination.componentaccessid = -1;
        destination.openedFromUrl = false;
        switch identifier{
        case "strengthsegue":
            destination.exercise = self.strengthexercise
            destination.exercisetype = .strength
        case "rangesegue":
            destination.exercise = self.rangeexercise
            destination.exercisetype = .range
        case "combinedsegue":
            destination.exercise = self.combinedexercise
            destination.exercisetype = .combined
        default:
            print("Nothing")
        }

    }
}

【问题讨论】:

  • self.navigationController?.pushViewController
  • 哦,谢谢。为什么 segues 不能通过导航控制器显示
  • 在故事板检查器中检查其kind,应该是Show (e.g. Push)

标签: ios swift xcode segue


【解决方案1】:

试试这个

self.navigationController?.pushViewController(destination, animated: true)

【讨论】:

    【解决方案2】:

    在您使用的代码中,

    self.navigationController?.present(destination, animated: true, completion: nil)
    

    这只会显示 UIViewController。

    改为使用,

    self.navigationController?.pushViewController(destination, animated: true)
    

    推送继承NavigationController的viewController。

    【讨论】:

      猜你喜欢
      • 2014-05-30
      • 2011-10-05
      • 1970-01-01
      • 2014-03-10
      • 2016-04-19
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多