收集的工具类-判断字符是否为空 view弹出提示框而不是vc

1./**判断输入框输入的内容是否为空 yes 表示为空 no 表示有内容**/

+ (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.因为弹出系统的UIAlertController是需要一个vc来present出来的, 所以有时候为了在一个自定义view弹出一个信息框,搜集了一个小方法

/**

*  弹出信息框 适用于弹出之后停留在当前页面 Class 传入的是什么类型的对象  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];

}

}

/**

*  弹出信息框 适用于弹出之后回到上一个页面

*

*  @param message 信息

*/

+ (void)showMessage:(NSString *)message

{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];

[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];

//得到当前的控制器

UIViewController *vc = [self getCurrentVC];

[vc presentViewController:alert animated:YES completion:nil];

}

/**

*  得到view所在的控制器

*

*  @param currentView 当前的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;

}

/**

*  得到当前的控制器

*/

+ (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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,158评论 1 6
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,585评论 1 14
  • 自从iOS9出来之后,需要使用UIAlertController来弹出弹框,不在提倡使用UIAlertView了,...
    南京杨小兵阅读 581评论 1 0
  • 诗人以为 青春是一首美丽的诗 屠夫以为 青春就是一把杀猪刀 上班族以为 青春就是工资 农民工以为 青春就是钢筋水泥...
    我爱领导的小生阅读 269评论 3 3
  • 我想我是快乐的,因为我头脑简单,四肢发达,很少想事情,简单执行的工作自己应该还是相当不错的呢。一直以来,我都希望自...
    今天安好阅读 347评论 0 0