Target-Action自带的代理

227 阅读1分钟

Target-Action自带的代理

  • 请阅读以下注释,关键是target可以为nil,更关键的是为nil以后的行为是顺着响应链来找
// add target/action for particular event. you can call this multiple times and you can specify multiple target/actions for a particular event.

// passing in nil as the target goes up the responder chain. The action may optionally include the sender and the event in that order

// the action cannot be NULL. Note that the target is not retained.

- (**void**)addTarget:(**nullable** **id**)target action:(**SEL**)action forControlEvents:(UIControlEvents)controlEvents;
  • 这样在Cell里的Button的响应事件想代理回Controller时,就可以利用这个特性。