Skip to content

Commit 467f0ed

Browse files
committed
fix alertview action presentviewcontroller bug,and public textFieldArray
1 parent e9e13e5 commit 467f0ed

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

TYAlertControllerDemo/TYAlertController/TYAlertView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ typedef NS_ENUM(NSUInteger, TYAlertActionStyle) {
3030
@property (nonatomic, weak, readonly) UILabel *titleLable;
3131
@property (nonatomic, weak, readonly) UILabel *messageLabel;
3232

33+
@property (nonatomic, strong, readonly) NSArray *textFieldArray;
34+
3335
// default 280, if 0 don't add width constraint,
3436
@property (nonatomic, assign) CGFloat alertViewWidth;
3537

TYAlertControllerDemo/TYAlertController/TYAlertView.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textFeild))c
265265
[self layoutTextFeilds];
266266
}
267267

268+
- (NSArray *)textFieldArray
269+
{
270+
return _textFeilds;
271+
}
272+
268273
#pragma mark - layout contenview
269274

270275
- (void)layoutContentViews
@@ -381,11 +386,11 @@ - (void)actionButtonClicked:(UIButton *)button
381386
{
382387
TYAlertAction *action = _actions[button.tag - kButtonTagOffset];
383388

389+
[self hideView];
390+
384391
if (action.handler) {
385392
action.handler(action);
386393
}
387-
388-
[self hideView];
389394
}
390395

391396
- (void)dealloc

TYAlertControllerDemo/ViewController.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ - (IBAction)showAlertViewAction:(id)sender {
3333
[alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) {
3434
NSLog(@"%@",action.title);
3535
}]];
36-
36+
37+
// 弱引用alertView 否则 会循环引用
38+
__typeof (alertView) __weak weakAlertView = alertView;
3739
[alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
40+
3841
NSLog(@"%@",action.title);
42+
for (UITextField *textField in weakAlertView.textFieldArray) {
43+
NSLog(@"%@",textField.text);
44+
}
3945
}]];
4046

4147
[alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {

0 commit comments

Comments
 (0)