UIView
には、複数のUILabel
があります。今、UIView
がクリックされたときに警告を追加したいと思います。ビューのクリックイベントは可能ですか?UIViewのタッチ後の警告
class viewController: UIViewController {
@IBOutlet weak var view1: UIView!
@IBOutlet weak var view2: UIView!
@IBOutlet weak var view3: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
func action(_ sender: UIView) {
// Create the alert controller
let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "title", style: UIAlertActionStyle.default) {
}
// Add the actions
alertController.addAction(okAction)
// Present the controller
self.present(alertController, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
action
は私の例のようになります機能:私の未完成のコードザッツ
。今私はそれを呼び出す方法を知ってそれを参照する必要がありますUIView
ありがとうございました。しかし、私はビューの数を取得していない、すべての 'タグ'は0 – j10
@ j10の値を持っています。あなたは直接代わりにUiViewをチェックすることができますあなたはtag.checkの代わりにチェックすることができます –
@全てのオブジェクトは 'tag'を' 0'としています。あなたが望むなら、 'Storyboard'に' tag'を設定することができます –