小编ani*_*rud的帖子

如何在 Xcode 中使用新的场景委托

我正在尝试更改标签的文本或在我的 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")
}
Run Code Online (Sandbox Code Playgroud)

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", …
Run Code Online (Sandbox Code Playgroud)

xcode viewcontroller swift ios13 uiscenedelegate

3
推荐指数
1
解决办法
3153
查看次数

标签 统计

ios13 ×1

swift ×1

uiscenedelegate ×1

viewcontroller ×1

xcode ×1