0
下面的文本使用uitextield並將其保存到標籤。可以說這是視圖控制器A.如何獲取保存的字符串並在swift中使用另一個視圖控制器?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var text: UITextField!
@IBOutlet weak var labelz: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func ritaOra(_ sender: Any) {
labelz.text = text.text
UserDefaults.standard.set(labelz.text, forKey: "myName")
text.text = ""
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
if let x = UserDefaults.standard.object(forKey: "myName") as? String
{
labelz.text = x
}
}
以下代碼是我在相機中使用的。可以說這是視圖控制器b。
let text = "Python"
let label = UILabel(frame: CGRect(x: 125, y: 400, width: self.view.frame.width, height: 300))
label.font = UIFont(name: label.font.fontName, size: 122)
label.textColor = UIColor.blue
label.alpha = 0.3
label.text = text
我該如何將視圖控制器a中的textview放置到let text =「Python」(視圖控制器b)當前的位置。
我用一個簡單的翻頁鍵導航。 –