Skip to content

Commit

Permalink
Rename the delegate property name.
Browse files Browse the repository at this point in the history
Since there are lots of subclasses may use the original default name
inside.
  • Loading branch information
xingheng committed Dec 17, 2018
1 parent 6d18e0c commit 171b7ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DSBaseViewController/DSBaseViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef void (^LoadViewControllerBlock)(__kindof DSBaseViewController *controlle

@interface DSBaseViewController : UIViewController <BuildViewDelegate>

@property (nonatomic, weak) id<BuildViewDelegate> delegate; // defaults to the instance of itself.
@property (nonatomic, weak) id<BuildViewDelegate> buildDelegate; // defaults to the instance of itself.

@property (nonatomic, assign, readonly) BOOL visible;

Expand Down
28 changes: 14 additions & 14 deletions DSBaseViewController/DSBaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ - (void)viewDidLoad

[self _setupAppearance];

if ([self.delegate respondsToSelector:@selector(buildSubview:controller:)]) {
[self.delegate buildSubview:self.view controller:self];
if ([self.buildDelegate respondsToSelector:@selector(buildSubview:controller:)]) {
[self.buildDelegate buildSubview:self.view controller:self];
} else {
DDLogError(@"%@ doesn't comform the required delegate methods of BuildViewDelegate!", self.delegate);
DDLogError(@"%@ doesn't comform the required delegate methods of BuildViewDelegate!", self.buildDelegate);
}

if (![self _hasInvalidStatusData]) {
Expand All @@ -58,7 +58,7 @@ - (void)viewWillAppear:(BOOL)animated
}

if (self.willAppearBlock) {
self.willAppearBlock( animated);
self.willAppearBlock(animated);
}

if (self.fReceivedMemoryWarning) {
Expand Down Expand Up @@ -167,13 +167,13 @@ + (void)setupWithOptionBlock:(LoadViewControllerBlock)loadOptionBlock

#pragma mark - Property

- (id<BuildViewDelegate>)delegate
- (id<BuildViewDelegate>)buildDelegate
{
if (!_delegate) {
_delegate = self;
if (!_buildDelegate) {
_buildDelegate = self;
}

return _delegate;
return _buildDelegate;
}

- (BOOL)visible
Expand Down Expand Up @@ -203,24 +203,24 @@ - (void)_setupAppearance

- (void)_loadDataSafely
{
if ([self.delegate respondsToSelector:@selector(loadDataForController:)]) {
[self.delegate loadDataForController:self];
if ([self.buildDelegate respondsToSelector:@selector(loadDataForController:)]) {
[self.buildDelegate loadDataForController:self];
}
}

- (void)_unloadDataSafely
{
if ([self.delegate respondsToSelector:@selector(loadDataForController:)]) {
[self.delegate tearDown:self];
if ([self.buildDelegate respondsToSelector:@selector(loadDataForController:)]) {
[self.buildDelegate tearDown:self];
}
}

- (BOOL)_hasInvalidStatusData
{
BOOL result = NO;

if ([self.delegate respondsToSelector:@selector(shouldInvalidateDataForController:)]) {
result = [self.delegate shouldInvalidateDataForController:self];
if ([self.buildDelegate respondsToSelector:@selector(shouldInvalidateDataForController:)]) {
result = [self.buildDelegate shouldInvalidateDataForController:self];
}

return result;
Expand Down
5 changes: 4 additions & 1 deletion Example/DSBaseViewController-Example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self setupDDLog];

[BaseViewController setupWithOptionBlock:^(__kindof DSBaseViewController *controller) {
controller.view.backgroundColor = [UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.0];
controller.view.backgroundColor = [UIColor colorWithRed:0.9f
green:0.9f
blue:0.9f
alpha:1.0];
}];

MainViewController *mainVC = [MainViewController new];
Expand Down

0 comments on commit 171b7ff

Please sign in to comment.