gpt4 book ai didi

swift - 如何使用单独的 View Controller 从弹出 View 更新 UIlabel

转载 作者:行者123 更新时间:2023-11-30 10:25:44 24 4
gpt4 key购买 nike

对 Swift 编程有点陌生,有一个关于从弹出 View 更新现有 uilabel 的问题。我遵循了本教程:

YouTube

我有一个名为“myViewController”的主 ViewController 和一个名为“popUp”的弹出 View Controller 。在 myViewController 上,我有 1 x UILabel,它是一个 socket :

@IBOutlet weak var myLabel: UILabel?

此标签填充在 viewDidLoad 中:

myLabel.text = "hello"

在弹出 View Controller 上我有 6 个按钮。每个按钮都有一个 IBAction:

  @IBAction func button1(_ sender: Any) {

//how do I set the uilabel from here to myViewController

dismiss(animated: true, completion: nil)
}

我像这样呈现弹出窗口:

Storyboard Segue

我希望能够调出弹出 Controller 并选择一个 UI 按钮,它会自动关闭并更新第一个 View Controller 上的标签。除了更新 UIlabel 之外,我可以让一切正常工作。

希望这是有道理的

谢谢

最佳答案

例如,您可以使用通知或协议(protocol),让主视图 Controller 知道弹出 Controller 上的按钮何时被按下。

https://developer.apple.com/documentation/foundation/nsnotificationcenter

https://docs.swift.org/swift-book/LanguageGuide/Protocols.html

关于swift - 如何使用单独的 View Controller 从弹出 View 更新 UIlabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60063412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com