Could somone help: I have situation where I'm calling a LoginViewController from my main ViewController and then via a delegate in the LoginViewcontroller calling back a function that fires off "self.dismissViewcontrolleranimated(view, animated: false, completion: nil) but the modal popup viewController just keeps poping back. Can anyone tell me what I have wrong.
Thanks Dave.
// ViewController.swift
import UIKit
import SafariServices
class ViewController: UIViewController, LoginViewDelegate {
var safariViewController: SFSafariViewController?
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
showPopUp()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func showPopUp()
{
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
if let loginVC = storyboard.instantiateViewControllerWithIdentifier(
"LoginViewController") as? LoginViewController {
loginVC.delegate = self
self.presentViewController(loginVC, animated: true, completion: nil)
}
}
// delegate function.
func didTapLoginButton() {
self.dismissViewControllerAnimated(false, completion: nil)
// if let authURL = GitHubAPIManager.sharedInstance.URLToStartOAuth2Login() {
// safariViewController = SFSafariViewController(URL: authURL)
// safariViewController?.delegate = self
// if let webViewController = safariViewController {
// self.presentViewController(webViewController, animated: true, completion: nil)
// }
// }
}
}
//
// LoginViewController.swift
// TestingPopUps
import UIKit
// this is a delegate function that can be used
// to call a funct+-*`*ion outside this class to do
// something on behafe of this class.
protocol LoginViewDelegate: class {
func didTapLoginButton()
}
class LoginViewController: UIViewController {
weak var delegate: LoginViewDelegate?
@IBAction func btnDismiss(sender: AnyObject) {
// Note: I tried dismissing here too with failure
//self.dismissViewControllerAnimated(false, completion: nil)
if let delegate = self.delegate {
delegate.didTapLoginButton()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I haven't actually run your code, but this part:
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) showPopUp() }
When the modal view dismissed, your ViewController's view will re-appear again. What do you think will happen after the view did re-appear.