Reload View Controller Swift 3

Asked

Viewed 445 times

0

Hello, I have an app and I entered the check of connection to the internet in viewDidAppear, I wanted to know how to give a Reload on this screen when the user click in RETRY of Alert, to make 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)
    }
}

1 answer

1


Creates a function that calls this connection check. Place a @Ibaction 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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.