Reload View Controller Swift 3

0

Hello, I have an app and I inserted the internet connection check in viewDidAppear, I wanted to know how I can reload this screen when the user clicks RETRY on the Alert, to do the check again.

override func viewDidAppear(_ animated: Bool) {
    if Reachability.isConnectedToNetwork() == true
    {
        print("Connected")
    }
    else
    {
        let controller = UIAlertController(title: "No Internet Detected", message: "This app requires an Internet connection", preferredStyle: .alert)

        // Create the actions
        let retry = UIAlertAction(title: "Retry", style: UIAlertActionStyle.default) {
            UIAlertAction in
            NSLog("Retry Pressed")
        }

        controller.addAction(retry)

        present(controller, animated: true, completion: nil)
    }
}
    
asked by anonymous 05.04.2017 / 03:46

1 answer

1

Create a function that calls this connection check. Place an @IBAction of a button to call this preference function:

override func viewDidAppear(_ animated: Bool) {
    verificaConexao()
}

func verificaConexao() {
    if Reachability.isConnectedToNetwork() == true {
        print("Connected")
    } else {
        let controller = UIAlertController(title: "No Internet Detected", message: "This app requires an Internet connection", preferredStyle: .alert)

        // Create the actions
        let retry = UIAlertAction(title: "Retry", style: UIAlertActionStyle.default) {
            UIAlertAction in
            NSLog("Retry Pressed")
        }

        controller.addAction(retry)

        present(controller, animated: true, completion: nil)
    }
}

@IBAction fun reloadButtonTapped(_ sender: Any) {
    verificaConexao
}
    
13.04.2017 / 14:34