UIButton remove all target-actions

后端 未结 5 936
广开言路
广开言路 2020-12-04 05:02

I have added multiple target-action-forControlEvents: to a UIButton. I\'d like to remove all of these in one go without deallocating anything. I will then set new targets.

5条回答
  •  感动是毒
    2020-12-04 05:28

    @progrmr's answer in Swift 2:

    button.removeTarget(nil, action: nil, forControlEvents: .AllEvents)
    

    and Swift 3:

    button.removeTarget(nil, action: nil, for: .allEvents)
    

    Note: Swift doesn't have NULL, so I tested replacing it with nil and it seems to work fine.

提交回复
热议问题