Skip to content

Commit 565ecee

Browse files
committed
为 QMUICommonTableViewController 和 QMUIModalPresentationViewController 加上 IBOutlet 的支持
1 parent 59a9c5b commit 565ecee

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

QMUIKit/UIComponents/QMUIModalPresentationViewController.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ typedef NS_ENUM(NSUInteger, QMUIModalPresentationAnimationStyle) {
102102
CGFloat _keyboardHeight;
103103
}
104104

105-
@property(nonatomic, weak) id<QMUIModalPresentationViewControllerDelegate> delegate;
105+
@property(nonatomic, weak) IBOutlet id<QMUIModalPresentationViewControllerDelegate> delegate;
106106

107107
/**
108108
* 要被弹出的浮层
109109
* @warning 当设置了`contentView`时,不要再设置`contentViewController`
110110
*/
111-
@property(nonatomic, strong) UIView *contentView;
111+
@property(nonatomic, strong) IBOutlet UIView *contentView;
112112

113113
/**
114114
* 要被弹出的浮层,适用于浮层以UIViewController的形式来管理的情况。
115115
* @warning 当设置了`contentViewController`时,`contentViewController.view`会被当成`contentView`使用,因此不要再自行设置`contentView`
116116
* @warning 注意`contentViewController`是强引用,容易导致循环引用,使用时请注意
117117
*/
118-
@property(nonatomic, strong) UIViewController<QMUIModalPresentationContentViewControllerProtocol> *contentViewController;
118+
@property(nonatomic, strong) IBOutlet UIViewController<QMUIModalPresentationContentViewControllerProtocol> *contentViewController;
119119

120120
/**
121121
* 设置`contentView`布局时与外容器的间距,默认为(20, 20, 20, 20)
@@ -134,7 +134,7 @@ typedef NS_ENUM(NSUInteger, QMUIModalPresentationAnimationStyle) {
134134
*
135135
* `QMUIModalPresentationViewController`会自动给自定义的`dimmingView`添加手势以实现点击遮罩隐藏浮层。
136136
*/
137-
@property(nonatomic, strong) UIView *dimmingView;
137+
@property(nonatomic, strong) IBOutlet UIView *dimmingView;
138138

139139
/**
140140
* 由于点击遮罩导致浮层被隐藏时的回调(区分于`hideWithAnimated:completion:`里的completion,这里是特地用于点击遮罩的情况)

QMUIKit/UIComponents/QMUIModalPresentationViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ - (void)didInitialized {
9090
[self initDefaultDimmingViewWithoutAddToView];
9191
}
9292

93+
- (void)awakeFromNib {
94+
[super awakeFromNib];
95+
if (self.contentViewController) {
96+
// 在 IB 里设置了 contentViewController 的话,通过这个调用去触发 contentView 的更新
97+
self.contentViewController = self.contentViewController;
98+
}
99+
}
100+
93101
- (void)dealloc {
94102
self.containerWindow = nil;
95103
}

QMUIKit/UIMainFrame/QMUICommonTableViewController.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,12 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
345345
@implementation QMUICommonTableViewController (QMUISubclassingHooks)
346346

347347
- (void)initTableView {
348-
_tableView = [[QMUITableView alloc] initWithFrame:self.view.bounds style:self.style];
349-
self.tableView.delegate = self;
350-
self.tableView.dataSource = self;
351-
[self.view addSubview:self.tableView];
348+
if (!_tableView) {
349+
_tableView = [[QMUITableView alloc] initWithFrame:self.view.bounds style:self.style];
350+
self.tableView.delegate = self;
351+
self.tableView.dataSource = self;
352+
[self.view addSubview:self.tableView];
353+
}
352354
}
353355

354356
- (BOOL)shouldHideTableHeaderViewInitial {

0 commit comments

Comments
 (0)