我有一个带有UITabBarController的应用程序作为根视图。我不希望我的用户必须登录才能查看该应用程序,因此所有用户都可以看到第一个选项卡(选项卡1)。现在其他选项卡应该锁定在LoginViewController后面。
我在锁定视图中有以下内容:
ActivityViewController.swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if AccessToken.current != nil {
// Do Stuff
}
else {
let vc = UIStoryboard(name:"Main", bundle:nil).instantiateViewController(withIdentifier: "UserLoginViewController")
self.navigationController?.pushViewController(vc, animated:false)
}
}
UserLoginViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
navigationItem.hidesBackButton = true
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if AccessToken.current != nil {
_ = self.navigationController?.popViewController(animated: true)
}
}
// Functions to handle login omitted
// I do the following once login is successful
_ = self.navigationController?.popViewController(animated: true)
// Close button to return to first no login required tab (Tab 1)
@IBAction func closeButtonPressed(_ sender: AnyObject) {
// Send back to the first index in the tab bar controller
self.navigationController?.tabBarController?.selectedIndex = 0
}
我有以下问题:
答案 0 :(得分:0)
通常的做法是提供您的登录控制器UserLoginViewController
,因此它会显示在UITabBarController
前面。然后在登录控制器内部,在登录成功时添加解除操作
if AccessToken.current != nil {
// Do Stuff
}
else {
let vc = UIStoryboard(name:"Main", bundle:nil).instantiateViewController(withIdentifier: "UserLoginViewController")
presentViewController(vc, animated: true, completion: nil)
}