I am developing an application for a username-password based system. My initial view controller is named LoginPageViewController
. If the user logs in successfully, a navigation controller named MyNavigationController
is loaded. All view controllers except LoginPageViewController
are accessed via a side-menu I found here: Side Menu Library by the help of MyNavigationController
.
View settings of my side menu are described in MyMenuTableViewController
and if any of table items is selected, relevant view controller is loaded from MyMenuTableViewController
. The problem is, I have also added "Logout" item to my side menu (or menu table, whatever you call) and if this item is selected, it makes an HTTP POST request to server to log out and should load the LoginPageViewController
which is my initial view controller (which is not embedded in MyNavigationControlelr
).
The problem is, although the logout request is handled successfully, I have been encountering problems while loading my initial view controller (LoginPageViewController
).
When I try this when Logout is selected:
self.presentViewController(destViewController, animated: true, completion: nil)
LoginPageViewController is being loaded but I get an message like:2014-10-30 16:59:26.038 iOpsGenie[2973:66509] Presenting view controllers on detached view controllers is discouraged <iOpsGenie.MyMenuTableViewController: 0x7f85e8fc3f10>.
and if I click any where on Login Page, my view disappears and only a white screen is left.
Then I tried implementing a method
func resetAppToFirstController() {
self.window?.rootViewController = LoginPageViewController(nibName: nil, bundle: nil)
}
in AppDelegate.swift and call it when Logout item is being selected:
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.resetAppToFirstController()
Then I got an error in second line of viewDidLoad function of LoginPageViewController like:
fatal error: unexpectedly found nil while unwrapping an Optional value
I know it became a very long question. I may be counted as a newbie on Swift and iOS programming and I tried to state the problem to prevent irrelevant responses. I really wonder what I am missing.
Best regards