gpt4 book ai didi

ios - 标签栏 Controller : Show Login Controller + Stop Double Tap on Tab Button

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

我有一个以 UITabBarController 作为 Root View 的应用程序。我不希望我的用户必须登录才能查看该应用程序,因此所有用户都可以看到第一个选项卡(选项卡 1)。现在其他选项卡应该锁定在 LoginViewController 后面。

我在锁定 View 上有以下内容:

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
}

我有以下问题:

  1. 在锁定的标签上按一次,正确显示登录屏幕。再次按下相同的选项卡,将关闭登录屏幕,动画显示登录屏幕隐藏的 View ,然后再次弹出登录屏幕。有什么办法可以阻止这种情况吗?

最佳答案

通常的做法是显示您的登录 Controller UserLoginViewController,因此它将显示在 UITabBarController 的前面。然后在登录 Controller 内部,添加登录成功时的关闭 Action

if AccessToken.current != nil {
// Do Stuff
}
else {
let vc = UIStoryboard(name:"Main", bundle:nil).instantiateViewController(withIdentifier: "UserLoginViewController")
presentViewController(vc, animated: true, completion: nil)
}

关于ios - 标签栏 Controller : Show Login Controller + Stop Double Tap on Tab Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251843/

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