gpt4 book ai didi

ios - backBarbuttonitem 什么都不做?

转载 作者:行者123 更新时间:2023-11-28 06:35:50 24 4
gpt4 key购买 nike

我已经以编程方式设置了导航

在 View Controller 中,我设置了一个后退按钮,并且只根据文档更改标题。然而,点击子 Controller 中的后退按钮什么都不做。

我错过了什么?

> in a viewController

let backItem = UIBarButtonItem()
backItem.title = ""
navigationItem.backBarButtonItem = backItem
self.navigationController?.pushViewController(secondViewController, animated: true)

最佳答案

您必须向按钮添加目标和操作,

let backItem = UIBarButtonItem()
backItem.title = ""
backItem.target = self
backItem.action = #selector(back)
navigationItem.backBarButtonItem = backItem
self.navigationController?.pushViewController(secondViewController, animated: true)

然后实现back()函数。

func back() {
// If your view controller was presented by a navigation controller
self.navigationController?.popViewControllerAnimated(true)

// If your view controller was presented modally
self.presentingViewController?.dismiss(animated: true, completion: nil)
}

关于ios - backBarbuttonitem 什么都不做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39112072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com