     override func viewWillAppear(animated: Bool) {
         super.viewWillAppear(animated)
         updateButtonStates()
+    }
+    override func viewDidAppear(animated: Bool) {
+        super.viewDidAppear(animated)
+        if loginCompletion != nil {
+            presentLoginUI()
+        }
     }
     
     func updateButtonStates() {

        
        // Reference to self must happen after super.init call
        smappeeController.delegate = self
    }
    
    // MARK: SmappeeControllerDelegate method
    func loginWithCompletion(completion: (SmappeeCredentialsResult) -> Void) {
        loginCompletion = completion
        
        let loginViewController = self.storyboard?.instantiateViewControllerWithIdentifier("loginViewController") as? LoginViewController
        

    
    func loginViewController(loginViewController: LoginViewController, didReturnUsername username: String, password: String) {

        loginCompletion?(smappeeLoginSuccess(username, password))
        loginCompletion = nil

        self.dismissViewControllerAnimated(true, completion: nil)
    }

    // MARK: ViewController life-cycle methods
