short :我不了解如何以编程方式添加默认后退按钮。
long :系统要求我编写一个iOS应用,但我没有任何以前的经验 遵循Nicola Zaghini给出的建议和代码。
在与文章一起提供的code中,我真的不明白 后退按钮从哪里来。
该应用具有三个屏幕
+
有一个WeatherLocation
按钮:
此按钮已添加到代码中,但找不到
以及WeatherDetails
中后退按钮的编码方式(请参见上文),以及单击后退按钮时执行的操作的编码方式。
我在网上搜索,发现如何在NavigationBar中设置按钮:
let leftBarButtonItem: UIBarButtonItem = {
let barButtonItem = UIBarButtonItem(title: "Left Item", style: .plain, target: self, action: nil)
barButtonItem.tintColor = UIColor.red
return barButtonItem
}()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.leftBarButtonItem = leftBarButtonItem
}
我还发现有一个backBarButtonItem 但我找不到如何正确使用此属性。
此外,在Nicola Zaghini的代码中,没有类似backBarButtonItem
的代码可以启用
后退按钮,而在xib和情节提要中都没有。
有人可以给我一些有关如何设置后退按钮的提示吗?
答案 0 :(得分:0)
非常感谢!!
在Nicola Zaghini的code中,拥有默认后退按钮的秘密(例如)存在于类navigateToWeatherDetail
中的函数WeatherListDefaultRouter
中,新的ViewController被推到NavigationController
:
func navigateToWeatherDetail(withLocation location: Location) {
if let weatherDetailVC = self.weatherDetailBuilder()?.buildWeatherDetailModule(withLocation: location) {
self.viewController?.navigationController?.pushViewController(weatherDetailVC, animated: true)
}
}