-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIViewController+DXKit.m
95 lines (82 loc) · 4.78 KB
/
UIViewController+DXKit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// UIViewController+DXTabTitle.m
// Fujitsu LifeCam
//
// Created by news365-macpro on 2017/3/22.
// Copyright © 2017年 Intelligent-earnings. All rights reserved.
//
#import "UIViewController+DXKit.h"
@implementation UIViewController (DXKit)
-(NSString *)getTabBarControllerTitle
{
return self.tabBarItem.title;
}
+ (UIViewController *)viewControllerFromMainStoryboardWithIdentifier:(NSString *)identifier
{
UIStoryboard *mainStroy = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
return [mainStroy instantiateViewControllerWithIdentifier:identifier];
}
- (UIAlertController *)showAlertControllerWithTitle:(NSString *)title
message:(NSString *)message
preferredStyle:(UIAlertControllerStyle)preferredStyle
actionTitle:(NSString *)actionTitle
actionStyle:(UIAlertActionStyle)actionStyle
actionHandler:(void (^)(UIAlertAction *action))handler
{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:preferredStyle];
UIAlertAction *saveAction = [UIAlertAction actionWithTitle:actionTitle style:actionStyle handler:handler];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alertVC addAction:saveAction];
[alertVC addAction:cancelAction];
[self presentViewController:alertVC animated:YES completion:nil];
return alertVC;
}
- (UIAlertController *)showAlertControllerStyleActionSheetWithTitle:(NSString *)title
message:(NSString *)message
actionTitle:(NSString *)actionTitle
actionStyle:(UIAlertActionStyle)actionStyle
actionHandler:(void (^)(UIAlertAction *action))handler
{
return [self showAlertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet actionTitle:actionTitle actionStyle:actionStyle actionHandler:handler];
}
- (UIAlertController *)showAlertControllerStyleAlertWithTitle:(NSString *)title
message:(NSString *)message
actionTitle:(NSString *)actionTitle
actionStyle:(UIAlertActionStyle)actionStyle
actionHandler:(void (^)(UIAlertAction *action))handler
{
return [self showAlertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert actionTitle:actionTitle actionStyle:actionStyle actionHandler:handler];
}
-(UIAlertController *)showAlertControllerWithTitle:(NSString *)title
message:(NSString *)message
actionTitle:(NSString *)actionTitle
actionHandler:(void (^)(UIAlertAction *action, UITextField *textField))handler
textFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *CancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Common.cancel", nil) style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *saveAction = [UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (handler) {
UITextField *textField = [alertController.textFields firstObject];
handler(action,textField);
}
}];
[alertController addTextFieldWithConfigurationHandler:configurationHandler];
[alertController addAction:CancelAction];
[alertController addAction:saveAction];
[self presentViewController:alertController animated:YES completion:nil];
return alertController;
}
- (UIAlertController *)showAlertControllerWithTitle:(NSString *)title
message:(NSString *)message
preferredStyle:(UIAlertControllerStyle)preferredStyle
actions:(NSArray<UIAlertAction *> *)actions
{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:preferredStyle];
for (UIAlertAction *action in actions) {
[alertVC addAction:action];
}
[self presentViewController:alertVC animated:YES completion:nil];
return alertVC;
}
@end