7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

addTarget:action:forControlEvents した時に引数も渡す

Last updated at Posted at 2015-12-25

UIButton などを押した時のアクション設定で addTarget:action:forControlEvents した時に一緒に引数を渡したい。

引数は選ぶことができないが、SenderとEventを渡すことができる。

// 引数なしの場合
button.addTarget(button, action: "touchedMe", forControlEvents: .TouchUpInside)

// Senderを渡す場合 : をセレクタの最後につける。イベントを発生させたオブジェクトになるので、この場合 button が送られる。
button.addTarget(button, action: "touchedMe:", forControlEvents: .TouchUpInside)

// Eventも渡す場合 :event: をつける
button.addTarget(button, action: "touchedMe:event:", forControlEvents: .TouchUpInside)

Passing parameters to addTarget:action:forControlEvents

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?