viewDidLoadでセットしたviewを、状況に応じて隠したり表示したりしたいのですが、下記のコードを実行しようとすると、下から3行目の、肝心の view1.hidden = true が、use of unsoloved identifier 'view1' というエラーを起こします。
どうしたら良いでしょうか?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() { super.viewDidLoad() let view1 = UIView(frame:CGRectMake(0, 0, 50, 50)) view1.backgroundColor = UIColor.greenColor() let button1 = UIButton(frame:CGRectMake(60, 0, 50, 50)) button1.backgroundColor = UIColor.redColor() button1.setTitle("ボタン", forState: .Normal) button1.setTitleColor(UIColor.whiteColor(), forState: .Normal) button1.addTarget(self, action: #selector(onClickMyButton), forControlEvents: .TouchUpInside) self.view.addSubview(view1) self.view.addSubview(button1) } func onClickMyButton(sender: UIButton){ view1.hidden = true }
}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/30 01:45