问题描述
我有 TabBarViewController,当我点击他的孩子时,会显示视图,称为 SettingsVC,在 SettingsVC 内部我有 tableview,底部有注销,当我点击注销时,我想关闭 SettingsVC 并显示LoginVC,但我无法实现这一点。我知道我应该使用委托、协议,但我做错了什么。代码如下,谢谢。
以下代码来自 SettingsVC
protocol PresentViewControllerDelegate: class {
func presentViewController(vc: LogInViewController)
}
class SettingsVC: UIViewController,UITabBarDelegate,UITabBarControllerDelegate {
public var presentDelegate: PresentViewControllerDelegate?
func present() {
presentDelegate?.presentViewController(vc: LogInViewController())
}
func logoutUser() {
networkManager.logout(endpoint: "/v1/auth/logout") { (session) in
switch session {
case .success:
print(session)
self.dismiss(animated: true,completion: nil)
self.present()
case .failure(let error):
print(error.localizedDescription)
}
}
}
extension SettingsVC: UITableViewDelegate,UITableViewDataSource {
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
let settings = SettingsEnums(rawValue: indexPath.row)
switch settings {
case .passcode:
print("passcode")
case .about:
print("about")
case .termsAndConditions:
print("terms and conditions")
case .privacyPolicy:
print("privacy policy")
case .visit:
print("visit")
case .logout:
logoutUser()
print("logout clicked")
default:
print("default")
}
}
}
然后我在 TabBarVC 中尝试了这个
extension TabBarViewController: PresentViewControllerDelegate {
func presentViewController(vc: LogInViewController) {
self.present(self,animated: true,completion: nil)
}
}
class TabBarViewController: UITabBarController,UINavigationControllerDelegate {
var settingsVC: SettingsVC!
override func viewDidLoad() {
super.viewDidLoad()
settingsVC.presentDelegate = self
}
}
我确实在注销方面取得了成功,并且设法关闭了 SettingsVC,但无法显示 LogInVC。如果您认为这会造成延迟并且可以看到“交换”,请您提出其他解决方案吗?
我很难理解代表.. 提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)