私人通讯录中遇到的注意点

来源:互联网 发布:指南数据库 编辑:程序博客网 时间:2024/06/02 09:08

1. 选择性的跳转   由当前控制器执行如下语句:

[selfperformSegueWithIdentifier:@"login2contact"sender:nil];


2.用户名密码错误的时候,弹出提醒  1S后自动消失 通过下面代码实现:


- (IBAction)loginBtnClick {

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

        if ([self.loginText.text isEqualToString:@"LW123"] && [self.passwordText.textisEqualToString:@"123456"]) {

            [selfperformSegueWithIdentifier:@"login2contact"sender:nil];

        }else{

            UIAlertController *controller = [UIAlertControlleralertControllerWithTitle:@"登录错误"message:@"用户名或者密码错误"preferredStyle:UIAlertControllerStyleActionSheet];

            UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"确认"style:UIAlertActionStyleDestructivehandler:nil];

            UIAlertAction  *cancleAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil];

            [controller addAction:okAction];

            [controller addAction:cancleAction];

            [selfpresentViewController:controller animated:YEScompletion:nil];

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

                [controller dismissViewControllerAnimated:YEScompletion:nil];

            });

            

        }

    });

              }



如果我们采用第三方框架MBProgressHUD 只需要简单的一两行代码就能实现 代码如下:

- (IBAction)loginBtnClick {

    [MBProgressHUDshowMessage:@"通讯管家正在拼命加载中..."];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

        if ([self.loginText.text isEqualToString:@"LW123"] && [self.passwordText.textisEqualToString:@"123456"]) {

            [MBProgressHUD hideHUD];

            [MBProgressHUD showSuccess:@"登录成功!欢迎回来"];

            [selfperformSegueWithIdentifier:@"login2contact"sender:nil];

        }else{

            [MBProgressHUD hideHUD];

            [MBProgressHUD showError:@"用户名或者密码错误"];

            


        }

    });

              }


这样子是不是很方便了呢
0 0
原创粉丝点击