将字符串与文本字段合并并返回swift中的标签

时间:2016-09-27 18:31:54

标签: ios swift ios10

目前,这只是将textField中的数据从第一个viewController传递到第二个viewController中的标签。我想在此textField之前连接一个字符串,以便在Label中显示它。

import UIKit

class ViewController: UIViewController {
    @IBOutlet var textField: UITextField!

    //var abs = "Greetings"

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let destviewcontroller : PassData = segue.destination as! PassData

        destviewcontroller.textLabel = textField.text!
        /* i want to add a string before this textField text to show it in label,
           for example "Greeings (whatever in textField)." */
    }
}

2 个答案:

答案 0 :(得分:1)

你想要这样的东西:

    android:theme="@android:style/Theme.Translucent.NoTitleBar"

但你应该考虑展开destviewcontroller.textLabel.text = "Greeings \(textField.text!)" 这样的

textField.text

因此,如果textField.text为空,您的应用程序将崩溃:D

答案 1 :(得分:0)

if let text = textField.text {
     destviewcontroller.textLabel.text = "Greeings (whatever in \(text))."
}