ボタンとコードのリンクの仕方がわかりません。
//ボタンクリック時に呼ばれる func onClick(sender:UIButton){ if sender.tag == ButtonCamera { openPicker(sourceType: UIImagePickerControllerSourceType.camera) }else if sender.tag == ButtomRead { openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary) } }
と書いたコードのButtonCamera のタグがついているボタンを上のボタンと、
ButtomRead のタグがついているボタンを下のボタンとリンクさせたいです。
写真右のOn Demand Resource Tagsに指定するのだと思っていたら、
違うように思いました(ボタンの指定ができないため)。
どのようにしたら(書けば)、ボタンとアクションがリンクするのでしょうか?
ちなみに全体には、
class FirstViewController:UIViewController, UINavigationControllerDelegate,UIImagePickerControllerDelegate{ //定数 let ButtonCamera = 0 let ButtomRead = 1 let ButtonWrite = 2 //変数 var imageView:UIImageView! var btnCamera:UIButton! var btnRead:UIButton! var btnWrite:UIButton! //ロード完了時に呼ばれる override func viewDidLoad() { super.viewDidLoad() //カメラボタン生成 self.view.addSubview(btnCamera) //読み込み self.view.addSubview(btnRead) // イメージビューの生成 self.view.addSubview(imageView) } //ボタンクリック時に呼ばれる func onClick(sender:UIButton){ if sender.tag == ButtonCamera { openPicker(sourceType: UIImagePickerControllerSourceType.camera) }else if sender.tag == ButtomRead { openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary) } }
のように書きました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/01 11:44
2017/01/01 11:55