【问题标题】:Printing Variable Unwind Segue - Xcode 8.0 Swift 3.0打印可变展开 Segue - Xcode 8.0 Swift 3.0
【发布时间】:2016-10-15 16:56:44
【问题描述】:

我想在按下条形按钮项(在导航栏上)时打印一个变量。当按下此条形按钮项时,会在设置变量的同时发生展开转场,然后将其打印到控制台(Xcode 底部的日志)。这是我的代码:

    @IBAction func doneNavItem(_ sender: AnyObject) {

    textField.text = var variableUnwind

    print(variableUnwind)

}

我知道在可以从 How to do something before unwind segue action? 打印变量之前触发了 unwind segue,但是这里的解决方案似乎不起作用,或者我可能读错了。

谢谢

【问题讨论】:

    标签: ios swift xcode uinavigationbar unwind-segue


    【解决方案1】:

    请将您的变量设置代码移至prepare for segue方法中。

    @IBOutlet weak var testTextField: UITextField!
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            var variableUnwind = ("StackOverFlow")
    
            print(variableUnwind)
            let textContents = testTextField.text
            print(textContents)
    
        }
    

    【讨论】:

    • 如果我想根据文本字段中的内容设置变量怎么办?
    • 我已经编辑了我的答案。您可以简单地为文本字段创建一个出口并在准备转场方法中访问它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多