简体   繁体   English

后退按钮显示然后迅速消失

[英]Back button shows then quickly disappears

Issue : Upon displaying the second view, the Back button shows and then quickly disappears.问题:在显示第二个视图时,“后退”按钮显示然后迅速消失。
I'd like the Back button to persist on the second view.我希望后退按钮保留在第二个视图上。

Setup: 2 views.设置: 2 个视图。
The button that opens the second view is done via a "Show" segue.打开第二个视图的按钮是通过“显示”segue 完成的。

SecondVC:第二个VC:

override func viewDidAppear(_ animated: Bool) {
        let controller = TipJarViewController<TipJarOptions>()
        self.present(controller, animated: false, completion: nil)
}

It seems to happen because of how I'm doing the viewDidAppear .这似乎是因为我如何做viewDidAppear It seems that I'm replacing the entire view with the self.present .看来我正在用self.present替换整个视图。 I'm not sure what to search for or modify so it can still show the Back button.我不确定要搜索或修改什么,因此它仍然可以显示“后退”按钮。

Bonus question: Wondering if I'm placing this code in the wrong section.奖励问题:想知道我是否将此代码放在错误的部分。 On the transition to the second view the screen is blank for a bit and then will show the view's contents.在转换到第二个视图时,屏幕会暂时空白,然后将显示视图的内容。 This doesn't seem like an optimal user experience.这似乎不是最佳的用户体验。 Open to any suggestions here.在这里接受任何建议。

问题的模拟器视图。

故事板视图

After moving present to first VC via Frankenstein's suggestion在通过科学怪人的建议将present转移给第一个 VC 之后将礼物移至第一个 vc 后

You don't need to segue into the second controller and then present.您无需进入第二个 controller 然后出现。 Instead, present directly instead of show the controller keeping it as rootViewController of a UINavigationController .相反,直接present而不是show controller 将其保持为rootViewControllerUINavigationController Do this on the action:对动作执行此操作:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let controller = UINavigationController(rootViewController: 
    TipJarViewController<TipJarOptions>())
    present(controller, animated: false, completion: nil)
}

Edit: To add back button in TipJarViewController , here is the code:编辑:要在TipJarViewController添加返回按钮,代码如下:

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(handleBack))
}

@objc func handleBack() {
    dismiss(animated: true)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM