1./**判斷輸入框輸入的內(nèi)容是否為空 yes 表示為空 no 表示有內(nèi)容**/
+ (BOOL) isBlankString:(NSString *)string {
if (string == nil || string == NULL) {
return YES;
}
if ([string isKindOfClass:[NSNull class]]) {
return YES;
}
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
return YES;
}
return NO;
}
2.因?yàn)閺棾鱿到y(tǒng)的UIAlertController是需要一個(gè)vc來(lái)present出來(lái)的揍很, 所以有時(shí)候?yàn)榱嗽谝粋€(gè)自定義view彈出一個(gè)信息框栗精,搜集了一個(gè)小方法
/**
*? 彈出信息框 適用于彈出之后停留在當(dāng)前頁(yè)面 Class 傳入的是什么類型的對(duì)象? view 或者Vc
*
*? @param message? ? ? 展示的信息
*? @param Class 傳入的是什么類型? view 或者Vc
*/
+ (void)showMessage:(NSString *)message Class:(id)class
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
if ([class isKindOfClass:[UIViewController class]]) {
UIViewController *vc = (UIViewController *)class;
[vc presentViewController:alert animated:YES completion:nil];
}else if ([class isKindOfClass:[UIView class]]){
UIView *view = (UIView *)class;
UIViewController *vc = [self getCurrentViewControllerWithView:view];
[vc presentViewController:alert animated:YES completion:nil];
}
}
/**
*? 彈出信息框 適用于彈出之后回到上一個(gè)頁(yè)面
*
*? @param message 信息
*/
+ (void)showMessage:(NSString *)message
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
//得到當(dāng)前的控制器
UIViewController *vc = [self getCurrentVC];
[vc presentViewController:alert animated:YES completion:nil];
}
/**
*? 得到view所在的控制器
*
*? @param currentView 當(dāng)前的view
*
*? @return 返回view所在的控制器
*/
+ (UIViewController *)getCurrentViewControllerWithView:(UIView *)currentView
{
for (UIView *view = currentView; view; view = view.superview)
{
UIResponder *nextResponder = [view nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
{
return (UIViewController *)nextResponder;
}
}
return nil;
}
/**
*? 得到當(dāng)前的控制器
*/
+ (UIViewController *)getCurrentVC
{
UIViewController *result = nil;
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIView *frontView = [[window subviews] objectAtIndex:0];
id nextResponder = [frontView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
result = nextResponder;
else
result = window.rootViewController;
return result;
}