Я пытаюсь изменить текст метки или показать предупреждение, когда мое приложение iOS становится активным из фонового состояния.
Когда я вызываю функцию в классе ViewController, нормально работает только метод print (). Но когда я хочу взаимодействовать с объектами этого класса, он показывает ошибки.
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)
}