//This is the label
let changeLbl = UILabel(frame: CGRect(x: 20, y: 170, width: 300, height: 21))
self.view.addSubview(changeLbl)
//This is the button
let submitButton = UIButton(type: .system) // let preferred over var here
submitButton.addTarget(self, action: #selector(buttonAction) , for: UIControlEvents.touchUpInside)
self.view.addSubview(submitButton)
//and this is action of above button
func buttonAction(sender: UIButton!) {
}
次のボタン機能で上記のラベルを呼び出したいですか? likeボタンアクションでラベルをプログラムで呼び出す/アクセスする方法は?
func buttonAction(sender: UIButton!) {
changeLbl.ishidden = true
//ここでラベルにアクセスしますが、この方法では動作しません。 }
あなたが直面している問題は何ですか? – shallowThought
ボタン機能のラベルにアクセスできない... @shallowThought – Bilal
「ラベルにアクセスできない」とはどういうことでしょうか?コンパイルエラー?ランタイムエラー?どちら? – shallowThought