I have an UITabBarController in my application that allows you to navigate between application tabs. One of these tabs is the User Profile. The problem is that I want to make both the profile and the login page on this tab so that the user can log into his account.
Logic: 1) An unauthorized user goes to the profile page and sees authorization forms there 2) The user fills in these forms and clicks the "Login" button 3) The data is sent to the server, sending the account access token 4) The application saves the token, removes the input controller and puts the controller profile.
I tried to do it through rootController, in which I wrote out the conditions for when and which controllers to issue, but there was a problem with the fact that the controller did a check every time the tab with the profile was pressed.
Past way:
class RootSettingsPage: UIViewController, UITextFieldDelegate { override func viewDidLoad() { super.viewDidLoad() navigationController?.isNavigationBarHidden = true view.backgroundColor = .white } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(false) switcherAddSubview() } func switcherAddSubview() { if UserDefaults.standard.value(forKey: "accessToken") != nil{ addProfilePage() } else { addLoginPage() } } func addLoginPage() { let LoginPage: LoginPageController = { let lp = LoginPageController() lp.homeController = self.navigationController return lp }() navigationController?.pushViewController(LoginPage, animated: false) } func addProfilePage(){ let ProfilePage: ProfilePageController = { let pp = ProfilePageController() return pp }() navigationController?.pushViewController(ProfilePage, animated: false) } }