Skip to content

Instantly share code, notes, and snippets.

@n-b
Last active August 3, 2021 10:08

Revisions

  1. n-b revised this gist Apr 19, 2013. 2 changed files with 0 additions and 4 deletions.
    2 changes: 0 additions & 2 deletions NBResponderChainUtilities.h
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,7 @@
    //
    // NBResponderChainUtilities.h
    //
    //
    // Created by Nicolas @ bou.io on 19/04/13.
    // Copyright (c) 2013 Nicolas Bouilleaud. All rights reserved.
    //

    #import <UIKit/UIKit.h>
    2 changes: 0 additions & 2 deletions NBResponderChainUtilities.m
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,7 @@
    //
    // NBResponderChainUtilities.m
    //
    //
    // Created by Nicolas @ bou.io on 19/04/13.
    // Copyright (c) 2013 Nicolas Bouilleaud. All rights reserved.
    //

    #import "NBResponderChainUtilities.h"
  2. n-b revised this gist Apr 19, 2013. 2 changed files with 11 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion NBResponderChainUtilities.h
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    @end

    @interface UIResponder (NBResponderChainUtilities)
    - (NSArray*) nb_responderChain; // List the -nextResponder starting at the receiver.
    - (NSArray*) nb_responderChain; // List the -nextResponder starting at the receiver
    @end


    10 changes: 10 additions & 0 deletions lddb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    (lldb) po NBResponderChain()
    $13 = 0x213dda70 <__NSArrayI 0x213dda70>(
    <UIActionSheet: 0x11915160; frame = (0 231; 320 337); opaque = NO; layer = <CALayer: 0x222b9c30>>,
    <UIView: 0x222c73b0; frame = (0 0; 320 568); opaque = NO; layer = <CALayer: 0x2229d2f0>>,
    <UIView: 0x2229d340; frame = (0 0; 320 568); opaque = NO; layer = <CALayer: 0x2229d3a0>>,
    <UIView: 0x11913dc0; frame = (0 0; 320 568); clipsToBounds = YES; layer = <CALayer: 0x2229d3d0>>,
    <_UIAlertOverlayWindow: 0x2226d4e0; frame = (0 0; 320 568); layer = <UIWindowLayer: 0x11911900>>,
    <UIApplication: 0xaa66b30>,
    <BicycletteApplicationDelegate: 0xab78c60>
    )
  3. n-b revised this gist Apr 19, 2013. 2 changed files with 53 additions and 5 deletions.
    25 changes: 25 additions & 0 deletions NBResponderChainUtilities.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    //
    // NBResponderChainUtilities.h
    //
    //
    // Created by Nicolas @ bou.io on 19/04/13.
    // Copyright (c) 2013 Nicolas Bouilleaud. All rights reserved.
    //

    #import <UIKit/UIKit.h>

    @interface UIView (NBResponderChainUtilities)
    - (UIView*) nb_firstResponder; // Recurse into subviews to find one that responds YES to -isFirstResponder
    @end

    @interface UIApplication (NBResponderChainUtilities)
    - (UIView*) nb_firstResponder; // in the -keyWindow
    @end

    @interface UIResponder (NBResponderChainUtilities)
    - (NSArray*) nb_responderChain; // List the -nextResponder starting at the receiver.
    @end


    UIView * NBFirstResponder(void); // in the app key window
    NSArray * NBResponderChain(void); // Starting at the first responder
    33 changes: 28 additions & 5 deletions NBResponderChainUtilities.m
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,23 @@
    //
    // NBResponderChainUtilities.m
    //
    //
    // Created by Nicolas @ bou.io on 19/04/13.
    // Copyright (c) 2013 Nicolas Bouilleaud. All rights reserved.
    //

    @implementation UIView (FirstResponder)
    #import "NBResponderChainUtilities.h"

    - (UIView*) nb_FirstResponder
    @implementation UIView (NBResponderChainUtilities)
    - (UIView*) nb_firstResponder
    {
    if ([self isFirstResponder]){
    return self;
    }

    for (UIView *subView in self.subviews)
    {
    UIView *firstResponder = [subView nb_FirstResponder];
    UIView *firstResponder = [subView nb_firstResponder];
    if (firstResponder != nil)
    {
    return firstResponder;
    @@ -19,11 +27,26 @@ - (UIView*) nb_FirstResponder
    }
    @end

    @implementation UIResponder (chain)
    @implementation UIApplication (NBResponderChainUtilities)
    - (UIView*) nb_firstResponder
    {
    return [[self keyWindow] nb_firstResponder];
    }
    @end

    @implementation UIResponder (NBResponderChainUtilities)
    - (NSArray*) nb_responderChain
    {
    return [@[self] arrayByAddingObjectsFromArray:[self.nextResponder nb_responderChain]];
    }

    @end

    UIView * NBFirstResponder(void)
    {
    return [[UIApplication sharedApplication] nb_firstResponder];
    }

    NSArray * NBResponderChain(void)
    {
    return [NBFirstResponder() nb_responderChain];
    }
  4. n-b renamed this gist Apr 19, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt → NBResponderChainUtilities.m
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@


    @implementation UIView (FirstResponder)

    - (UIView*) nb_FirstResponder
  5. n-b created this gist Apr 19, 2013.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@


    @implementation UIView (FirstResponder)

    - (UIView*) nb_FirstResponder
    {
    if ([self isFirstResponder]){
    return self;
    }

    for (UIView *subView in self.subviews)
    {
    UIView *firstResponder = [subView nb_FirstResponder];
    if (firstResponder != nil)
    {
    return firstResponder;
    }
    }
    return nil;
    }
    @end

    @implementation UIResponder (chain)

    - (NSArray*) nb_responderChain
    {
    return [@[self] arrayByAddingObjectsFromArray:[self.nextResponder nb_responderChain]];
    }

    @end