Skip to content

Commit c504b8f

Browse files
author
Larry Tin
committed
增加部分注释
1 parent 18ef563 commit c504b8f

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

GDDataDrivenView/Classes/MVP/GDDPresenter.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
// Created by Larry Tin on 16/9/20.
33
//
44

5-
#import <Foundation/Foundation.h>
5+
#import <UIKit/UIKit.h>
66
@protocol GDDView;
77

88
@protocol GDDPresenter
99

10-
- (void)update:(id <GDDView>)view withData:(id)data;
10+
/**
11+
* @param viewController viewDidLoad 这时已被调用
12+
* @param data
13+
*/
14+
- (void)update:(UIViewController<GDDView> *)viewController withData:(id)data;
1115

1216
@optional
1317
/**
14-
* @param owner 使用弱引用持有, 否则将导致循环引用
15-
* @return
18+
* 必须在 UIViewController 的 init 初始化阶段创建 Presenter
19+
* @param owner 使用弱引用持有 owner, 否则将导致循环引用
1620
*/
1721
- (instancetype)initWithOwner:(id)owner;
1822

19-
@end
23+
@end

GDDataDrivenView/Classes/MVP/GDDView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @return 当不实现该方法时, 默认根据类名约定查找并复用之前已创建的 Presenter 实例, 若不存在则创建新的实例并缓存
1313
*
1414
* XyzViewController -> XyzPresenter
15-
* AbcRender -> AbcPresenter
1615
*
1716
*/
1817
- (id <GDDPresenter>)presenter;

GDDataDrivenView/Classes/MVP/GDDViewPresenter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@protocol GDDViewPresenter <GDDPresenter>
99

10-
- (void)update:(id)view withData:(id)data;
10+
- (void)update:(UIView<GDDView> *)view withData:(id)data;
1111

1212
@optional
1313
- (UIView *) view;

GDDataDrivenView/Classes/RenderPresenter/GDDRender.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44

55
#import <Foundation/Foundation.h>
66
#import "GDDView.h"
7+
#import "GDDRenderPresenter.h"
78

89
@protocol GDDRender <GDDView>
910

11+
@optional
12+
/**
13+
* @return 当不实现该方法时, 默认根据类名约定查找并复用之前已创建的 RenderPresenter 实例, 若不存在则创建新的实例并缓存
14+
*
15+
* AbcRender -> AbcPresenter
16+
*
17+
*/
18+
- (id <GDDRenderPresenter>)presenter;
19+
1020
@end

GDDataDrivenView/Classes/ViewControllerPresenter/GDDViewControllerTransition.m

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#import "GDDViewControllerTransition.h"
66
#import <objc/runtime.h>
7-
#import "GDCMessageHandler.h"
87

98
// The address of this variable is used as a key for obj_getAssociatedObject.
109
static const char kPresenterKey = 0;
@@ -36,7 +35,7 @@ @implementation GDDViewControllerTransition {
3635

3736
- (id <GDDTransitionBuilder> (^)(Class viewControllerClass))to {
3837
return ^id <GDDTransitionBuilder>(Class viewControllerClass) {
39-
_viewController = [viewControllerClass instancesRespondToSelector:@selector(initWithPayload:)] ? [[viewControllerClass alloc] initWithPayload:_data] : [[viewControllerClass alloc] init];
38+
_viewController = [[viewControllerClass alloc] init];
4039
return self;
4140
};
4241
}
@@ -152,10 +151,6 @@ - (void)displayAndRefresh {
152151

153152
if (!shouldPush) {
154153
// 动画: 仅在 present 时有效
155-
// if (viewOptions.transition) {
156-
// controller.transitioningDelegate = viewOptions.transition;
157-
// controller.modalPresentationStyle = UIModalPresentationCustom;
158-
// }
159154
controller.modalTransitionStyle = _viewOption.modalTransitionStyle;
160155
controller.modalPresentationStyle = _viewOption.modalPresentationStyle;
161156
}
@@ -168,14 +163,14 @@ - (void)displayAndRefresh {
168163
if (!controller.isViewLoaded) {
169164
[controller view]; // force viewDidLoad to be called
170165
}
171-
[presenter update:(id <GDDView>) controller withData:_data];
166+
[presenter update:controller withData:_data];
172167
});
173168
return;
174169
}
175170

176171
[self config:YES]; // 某些 ViewOption 需要在 present 之前设置才会生效
177172
[top presentViewController:_stackMode == PRESENT ? controller : [[UINavigationController alloc] initWithRootViewController:controller] animated:YES completion:^{
178-
[presenter update:(id <GDDView>) controller withData:_data];
173+
[presenter update:controller withData:_data];
179174
}];
180175
[self config:NO];
181176
}
@@ -209,9 +204,6 @@ - (void)config:(BOOL)eagerly {
209204
if (toolBar != GDPBBool_Default && GDPBBool_IsValidValue(toolBar)) {
210205
[controller.navigationController setToolbarHidden:toolBar == GDPBBool_False animated:NO];
211206
}
212-
// if (options[optionStatusBarOrientation]) {
213-
// [[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation) [options[optionStatusBarOrientation] integerValue]];
214-
// }
215207
if (viewOption.deviceOrientation) {
216208
viewOption.deviceOrientation = UIDeviceOrientationUnknown;
217209
[[UIDevice currentDevice] setValue:@(viewOption.deviceOrientation) forKey:@"orientation"];
@@ -251,7 +243,7 @@ + (void)replaceRootViewController:(UIViewController *)controller {
251243
if (rootViewController.presentedViewController) { // 避免内存泄漏, 以释放 rootViewController 和 rootViewController.presentedViewController
252244
[rootViewController dismissViewControllerAnimated:YES completion:nil];
253245
}
254-
UIApplication.sharedApplication.keyWindow.rootViewController = controller;
246+
UIApplication.sharedApplication.delegate.window.rootViewController = controller; // keyWindow 在 makeKeyAndVisible 执行前为nil
255247
}
256248

257249
+ (UIViewController *)findViewController:(Class)viewControllerClass {

0 commit comments

Comments
 (0)