Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates delegation of DCIntrospect and update the demo. #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions DCIntrospect/DCIntrospect.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#ifdef DEBUG

@protocol DCIntrospectDelegate;

@interface UIView (debug)

- (NSString *)recursiveDescription;
Expand Down Expand Up @@ -51,6 +53,9 @@

@property (nonatomic) BOOL showingHelp;

// Weak would have been better but the project is iOS 4 compatible.
@property (nonatomic, assign) id<DCIntrospectDelegate> delegate;

///////////
// Setup //
///////////
Expand Down Expand Up @@ -153,3 +158,9 @@
- (BOOL)shouldIgnoreView:(UIView *)view;

@end

@protocol DCIntrospectDelegate <NSObject>

- (BOOL)introspect:(DCIntrospect *)theIntrospect shouldConsumeKeyboardInput:(NSString *)theInput;

@end
5 changes: 5 additions & 0 deletions DCIntrospect/DCIntrospect.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ @implementation DCIntrospect
@synthesize currentView, originalFrame, originalAlpha;
@synthesize currentViewHistory;
@synthesize showingHelp;
@synthesize delegate;

#pragma mark Setup

Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

#import <UIKit/UIKit.h>
#import "DCIntrospect.h"

@interface DCIntrospectDemoViewController : UIViewController <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
@interface DCIntrospectDemoViewController : UIViewController <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource, DCIntrospectDelegate>
{
}

Expand Down
17 changes: 17 additions & 0 deletions DCIntrospectDemo/DCIntrospectDemo/DCIntrospectDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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