非常基本的問題,感謝您的幫助初學者斯威夫特 - 無法更改UILabel.text存儲財產對象
試圖通過查閱存儲財產對象(jName)來改變一個UILabel的文本,這樣你就可以改變未來/添加更多的名稱/標籤,而不是隻是明確地聲明firstName.text =「Joe Bloggs」
不明白爲什麼它不會讓我改變文本到jName的存儲屬性?我嘗試了提升房產的價值,但這也沒有幫助。任何人都知道構建這個最好的方法?
class ViewController: UIViewController {
@IBOutlet var firstName: UILabel!
@IBOutlet var thirdName: UILabel!
struct jName {
var fName: String = "Joe"
var lName: String = "Blogs"
init(fName: String, lName: String) {
self.fName = fName
self.lName = lName
}
}
override func viewDidLoad() {
super.viewDidLoad()
assignLabels()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func assignLabels() {
firstName.text = jName.fName
thirdName.text = jName.lName
}
}