Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing the iOS Responder Chain

Introducing the iOS Responder Chain

Presented at Brisbane Cocoaheads, October 2015

lachlanroche

October 06, 2015
Tweet

More Decks by lachlanroche

Other Decks in Programming

Transcript

  1. to target: AnyObject? • “The object to receive the action

    message. If to is nil, the app sends the message to the first responder, from whence it progresses up the responder chain until it is handled.” • First Responder in IB means target == nil
  2. “…from whence it progresses up the responder chain until it

    is handled.” • Initial receiver is the First Responder. • canPerformAction(_ action: Selector, withSender sender: AnyObject?) -> Bool • nextResponder() -> UIResponder?
  3. UITableViewCell • Works with UITableView to implement context menus. •

    If you want to send an action via the responder chain, override canPerformAction:withSender:
  4. Finding First Responder static __weak id currentFirstResponder; @implementation UIResponder (FirstResponder)

    + (id) currentFirstResponder { currentFirstResponder = nil; [[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil]; return currentFirstResponder; } - (void) findFirstResponder:(id)sender { currentFirstResponder = self; } @end