在下图中,我在导航栏中有一个“返回”按钮,我希望它关闭“条形码扫描仪”选项卡并将我带到点击“返回”按钮之前的视图。这怎么可能?
问问题
55 次
3 回答
1
您的请求是不正确的用户界面。选项卡不应包含用于转到上一个选项卡的后退按钮,我真的希望“关闭”选项卡并不意味着您要删除它。
除此之外,您可以更改活动选项卡 UITabBar.setSelectedItem。但真的在你的情况下不要这样做。
于 2017-05-10T11:29:57.647 回答
0
您可以覆盖 ViewDidLoad 中的后退按钮,例如:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.back(_:)))
}
func back(_ sender: AnyObject) {
//if you want to go to previous view use this code
self.navigationController?.popViewController(animated: true)
//if you want to go to a tab bar view use this code
//index of your tab bar
tabBarController?.selectedIndex = 1
}
于 2017-05-10T11:50:23.367 回答
0
您加载的视图控制器都按您查看它们的顺序堆叠。要返回上一个视图,只需关闭最后一个视图控制器。您可以使用以下代码:
@IBAction func backButtonPressed(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
希望这应该可以解决问题。
于 2017-05-10T11:33:01.197 回答