UIButton remove all target-actions

后端 未结 5 935
广开言路
广开言路 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:33

    Swift 2:

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

    Swift 3 & 4:

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

    Objective-C:

    [actionButton removeTarget: nil action: NULL forControlEvents: UIControlEventAllEvents];
    

    Hope it helps.

提交回复
热议问题