Last active
August 3, 2021 10:08
-
-
Save n-b/5420684 to your computer and use it in GitHub Desktop.
Chain Responder Debugging Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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> | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NBResponderChainUtilities.h | |
// | |
// Created by Nicolas @ bou.io on 19/04/13. | |
// | |
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NBResponderChainUtilities.m | |
// | |
// Created by Nicolas @ bou.io on 19/04/13. | |
// | |
#import "NBResponderChainUtilities.h" | |
@implementation UIView (NBResponderChainUtilities) | |
- (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 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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment