Ios 使用快速操作时缺少导航栏
我正在为我的应用程序使用快速操作,它们工作正常,只是缺少导航栏(没有后退按钮)。这是我的密码:Ios 使用快速操作时缺少导航栏,ios,swift,Ios,Swift,我正在为我的应用程序使用快速操作,它们工作正常,只是缺少导航栏(没有后退按钮)。这是我的密码: func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { let vc = storyboard.instantiateViewControll
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let vc = storyboard.instantiateViewController(withIdentifier: "AddViewController") as! AddViewController
switch shortcutItem.type {
case "AddIncome":
vc.type = .income
app?.mainVC.dismiss(animated: false, completion: nil)
app?.mainVC.present(vc, animated: true, completion: nil)
case "AddExpense":
vc.type = .expense
app?.mainVC.dismiss(animated: false, completion: nil)
app?.mainVC.present(vc, animated: true, completion: nil)
default:
break;
}
}
mainVC
实际上是视图控制器,我在其中显示AddViewController
,我的导航栏缺失的vc
我似乎看不出问题出在哪里。我需要做一些额外的工作才能使它正常工作吗?您可以考虑以下几点:
@在显示任何视图控制器时,需要添加导航控制器以显示导航栏。试试下面的代码
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let vc = storyboard.instantiateViewController(withIdentifier: "AddViewController") as! AddViewController
var nav = UINavigationController()
nav.viewControllers = [vc]
switch shortcutItem.type {
case "AddIncome":
vc.type = .income
app?.mainVC.dismiss(animated: false, completion: nil)
app?.mainVC.present(nav, animated: true, completion: nil)
case "AddExpense":
vc.type = .expense
app?.mainVC.dismiss(animated: false, completion: nil)
app?.mainVC.present(nav, animated: true, completion: nil)
default:
break;
}
}
现在您可以在AddViewController上添加后退按钮
override func viewDidLoad() {
super.viewDidLoad()
let button = UIBarButtonItem(title: "Back", style:.plain, target: self, action: #selector(self.moveToPreviousScreen))
self.navigationItem.backBarButtonItem = button
}
希望它能帮助您,谢谢。当您以modally方式呈现视图控制器时,不会有“后退”按钮。@dan:您说得对。我只是以一种方式介绍他们。只需要找到导航控制器并推一下。请提供此答案,我将接受。