diff --git a/DCIntrospect/DCIntrospect.h b/DCIntrospect/DCIntrospect.h index f7178bc..574d96e 100644 --- a/DCIntrospect/DCIntrospect.h +++ b/DCIntrospect/DCIntrospect.h @@ -17,6 +17,8 @@ #ifdef DEBUG +@protocol DCIntrospectDelegate; + @interface UIView (debug) - (NSString *)recursiveDescription; @@ -51,6 +53,9 @@ @property (nonatomic) BOOL showingHelp; +// Weak would have been better but the project is iOS 4 compatible. +@property (nonatomic, assign) id delegate; + /////////// // Setup // /////////// @@ -153,3 +158,9 @@ - (BOOL)shouldIgnoreView:(UIView *)view; @end + +@protocol DCIntrospectDelegate + +- (BOOL)introspect:(DCIntrospect *)theIntrospect shouldConsumeKeyboardInput:(NSString *)theInput; + +@end \ No newline at end of file diff --git a/DCIntrospect/DCIntrospect.m b/DCIntrospect/DCIntrospect.m index cc4b4cf..2a0dd32 100644 --- a/DCIntrospect/DCIntrospect.m +++ b/DCIntrospect/DCIntrospect.m @@ -77,6 +77,7 @@ @implementation DCIntrospect @synthesize currentView, originalFrame, originalAlpha; @synthesize currentViewHistory; @synthesize showingHelp; +@synthesize delegate; #pragma mark Setup @@ -431,6 +432,10 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r return NO; } + if ([self.delegate introspect:self shouldConsumeKeyboardInput:string]) { + return NO; + } + if ([string isEqualToString:kDCIntrospectKeysInvoke]) { [self invokeIntrospector]; diff --git a/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.h b/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.h index cd062d4..baeebe9 100644 --- a/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.h +++ b/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.h @@ -7,8 +7,9 @@ // #import +#import "DCIntrospect.h" -@interface DCIntrospectDemoViewController : UIViewController +@interface DCIntrospectDemoViewController : UIViewController { } diff --git a/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.m b/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.m index 2706df3..5ccb40f 100644 --- a/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.m +++ b/DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.m @@ -16,6 +16,8 @@ @implementation DCIntrospectDemoViewController - (void)dealloc { [[DCIntrospect sharedIntrospector] removeNamesForViewsInView:self.view]; + // It is important for the delegate to be set as nil to prevent crashes. + [DCIntrospect sharedIntrospector].delegate = nil; [activityIndicator release]; [label release]; @@ -33,6 +35,8 @@ - (void)viewDidLoad { [super viewDidLoad]; + [DCIntrospect sharedIntrospector].delegate = self; + // set the activity indicator to a non-integer frame for demonstration self.activityIndicator.frame = CGRectOffset(self.activityIndicator.frame, 0.5, 0.0); [[DCIntrospect sharedIntrospector] setName:@"activityIndicator" forObject:self.activityIndicator accessedWithSelf:YES]; @@ -108,4 +112,17 @@ - (IBAction)sliderChanged:(id)sender { } +#pragma mark - DCIntrospectDelegate methods + +- (BOOL)introspect:(DCIntrospect *)theIntrospect shouldConsumeKeyboardInput:(NSString *)theInput { + if ([theInput isEqualToString:@"z"]) { + if (self.label.backgroundColor == nil) { + self.label.backgroundColor = [UIColor greenColor]; + } else { + self.label.backgroundColor = nil; + } + } + return NO; +} + @end