I'm trying to change a Label's text or show an alert when my iOS app becomes active from the background state.
When I call a function in the ViewController class only the print() method works fine. But when I want to interact with the objects in that class, it shows errors.
SceneDelegate.swift:
var vc = ViewController()
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
vc.showMessage("Test message")
}
ViewController.swift:
@IBOutlet weak var textLabel: UILabel!
func showMessage(_ incomingMessage:String!) {
let warning = UIAlertController(title: "Warning", message: incomingMessage, preferredStyle: .alert)
let aButton = UIAlertAction(title: "OK", style: .cancel, handler: nil)
warning.addAction(aButton)
self.present(warning, animated: true)
textLabel.text = incomingMessage
print("message is : " + incomingMessage)
}