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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// UIViewController+Additions.m
// RealEstateManagement
//
// Created by Z on 16/7/23.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "UIViewController+Additions.h"
@interface UIViewController (Addtions)
@end
@implementation UIViewController (Additions)
- (id)storyboardType:(STORYBOARD_TYPE_)type identifier:(NSString *)identifier
{
UIStoryboard *storyboard;
switch (type) {
case STORYBOARD_TYPE_MAIN: {
storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
break;
}
case STORYBOARD_TYPE_REPAIR: {
storyboard = [UIStoryboard storyboardWithName:@"Repair" bundle:nil];
break;
}
case STORYBOARD_TYPE_INSPECT: {
storyboard = [UIStoryboard storyboardWithName:@"Inspect" bundle:nil];
break;
}
case STORYBOARD_TYPE_READING: {
storyboard = [UIStoryboard storyboardWithName:@"Reading" bundle:nil];
break;
}
case STORYBOARD_TYPE_SUGGEST: {
storyboard = [UIStoryboard storyboardWithName:@"Suggest" bundle:nil];
break;
}
case STORYBOARD_TYPE_SALEINPUT: {
storyboard = [UIStoryboard storyboardWithName:@"SaleInput" bundle:nil];
break;
}
case STORYBOARD_TYPE_OPERINSPECT:{
storyboard = [UIStoryboard storyboardWithName:@"OperInspect" bundle:nil];
break;
}
case STORYBOARD_TYPE_TENANT: {
storyboard = [UIStoryboard storyboardWithName:@"TenantCommunicate" bundle:nil];
break;
}
case STORYBOARD_TYPE_BRIEF_REPORT:{
storyboard = [UIStoryboard storyboardWithName:@"BriefReport" bundle:nil];
break;
}
case STORYBOARD_TYPE_AMMETER:{
storyboard = [UIStoryboard storyboardWithName:@"Ammeter" bundle:nil];
break;
}
case STORYBOARD_TYPE_TODO:{
storyboard = [UIStoryboard storyboardWithName:@"ToDo" bundle:nil];
break;
}
case STORYBOARD_TYPE_YUEXING:{
storyboard = [UIStoryboard storyboardWithName:@"YueXing" bundle:nil];
break;
}
case STORYBOARD_TYPE_TENNANT_MANAGEMENT:{
storyboard = [UIStoryboard storyboardWithName:@"TenantManagement" bundle:nil];
break;
}
case STORYBOARD_TYPE_BRAND_MANAGEMENT:{
storyboard = [UIStoryboard storyboardWithName:@"BrandManagement" bundle:nil];
break;
}
case STORYBOARD_TYPE_STATEMENT:{
storyboard = [UIStoryboard storyboardWithName:@"Statement" bundle:nil];
break;
}
}
return [storyboard instantiateViewControllerWithIdentifier:identifier];
}
/**
* 从不同storyBoard获取控制器(这里storyBoard的id必须和类名一致)
*
* @param type storyBoard类型
*
* @return 对应控制器
*/
+ (id __nonnull)viewControllerWithStoryBoardType:(STORYBOARD_TYPE_)type
{
NSString *identifier = NSStringFromClass(self);
UIViewController *vc = [[self alloc] init];
return [vc storyboardType:type identifier:identifier];
}
- (void)alertTitle:(NSString *__nullable)title
msg:(NSString *__nullable)msg
okAction:(void (^__nullable)(UIAlertAction *__nullable action))okAction
cancelAction:(void (^__nullable)(UIAlertAction *__nullable action))cancelAction
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:okAction];
[alert addAction:ok];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:cancelAction];
[alert addAction:cancel];
if (self.navigationController) {
[self.navigationController presentViewController:alert animated:YES completion:nil];
}else{
[self presentViewController:alert animated:YES completion:nil];
}
}
- (BOOL)j_popToViewController:(Class _Nonnull)vc {
for (id obj in self.navigationController.viewControllers) {
if ([obj isKindOfClass:vc]) {
[self.navigationController popToViewController:obj animated:YES];
return YES;
break;
}
}
return NO;
}
- (void)hasPermission:(BOOL)permission yes:(void (^)(void))yes no:(void (^)(void))no
{
if (permission) {
if (yes) {
yes();
}
} else {
if (no) {
no();
}
}
}
- (BOOL)regIsValidDecimalInputtextField:(UITextField *)textField Range:(NSRange)range replacementString:(NSString *)string
{
//获取改变之后的字符串
NSMutableString *futureString = [NSMutableString stringWithString:textField.text];
[futureString insertString:string atIndex:range.location];
//金额输入
NSString *reg = @"^-?$|^-0$|^\\d?$|^-?[1-9]\\d*$|^-?0\\.\\d*$|^-?[1-9]\\d*\\.\\d{0,2}$";
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", reg];
return [numberPre evaluateWithObject:futureString];
}
@end