美文网首页
聊天(3)---登陆界面

聊天(3)---登陆界面

作者: 箫声_筱昇 | 来源:发表于2016-05-06 21:50 被阅读61次

登录界面

  • 简单界面
屏幕快照 2016-05-06 下午8.40.47.png
  • 1:导入头文件
#import "LoginViewController.h"
#import "EMSDK.h"
#import "RegisterViewController.h"
#import "UserInfoModel.h"
#import "AppDelegate.h"
#import "MainViewController.h"
  • 2:声明需要构建页面的属性
@interface LoginViewController ()
@property (nonatomic, strong) UILabel *label_1;//登录
@property (nonatomic, strong) UILabel *label_2;//密码

@property (nonatomic, strong) UITextField *textfield_1;//用户名
@property (nonatomic, strong) UITextField *textfield_2;//密码
@property (nonatomic, strong) UIButton *button_1;
@property (nonatomic, strong) UIButton *button_2;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView;//风火轮
@end
  • 为了确保使用的登录界面是同一个界面,使用单例
+ (LoginViewController *)sharedLoginView{
    static LoginViewController *loginVC = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        loginVC = [[LoginViewController alloc] init];
    });
    return loginVC;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    {
        [self.view addSubview:self.label_1];
        [self.view addSubview:self.label_2];
        [self.view addSubview:self.textfield_1];
        [self.view addSubview:self.textfield_2];
        [self.view addSubview:self.button_1];
        [self.view addSubview:self.button_2];
    }
    self.navigationItem.title = @"登录";
}
#pragma mark-------button 的登陆方法的方法回调按钮
- (void)loginAction:(UIButton *)sender{
    BOOL isNotSuccess = [self isSucces];
    
    if (isNotSuccess) {  //说明信息不能为空
        [self.activityIndicatorView startAnimating];
        /**
         *  将登陆操作放到子线程中.比较耗时
         */
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //登录
            EMError *error = [[EMClient sharedClient] loginWithUsername:self.textfield_1.text password:self.textfield_2.text];
            if (!error) {
                //回到主线程
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.activityIndicatorView stopAnimating];
                    [self.activityIndicatorView removeFromSuperview];
                    [self myAlerMessage:@"登陆成功"];
                    //需要将用户信息保存到本地
                    UserInfoModel  *userInfoModel = [[UserInfoModel alloc] init];
                    userInfoModel.name = self.textfield_1.text;
                    userInfoModel.isLogin = YES;//要将 isLogin 改为 yes;
                    //自动登录
                    [[EMClient sharedClient].options setIsAutoLogin:YES];
                    
                    //跳转到主界面
                    AppDelegate *delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
                    MainViewController *mainVC = [[MainViewController alloc] init];
                    delegate.window.rootViewController = mainVC;
                    //发送属性列表的广播
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshFriendList" object:nil];
                });
                NSLog(@"登陆成功");
            }else{
                //回到主线程
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.activityIndicatorView stopAnimating];
                    [self.activityIndicatorView removeFromSuperview];
                    [self myAlerMessage:[NSString stringWithFormat:@"登录---失败:%d",error.code]];
                });
            }
        });
    }
}
#pragma mark-------label\textfield\button懒加载
- (UILabel *)label_1{
    if (!_label_1) {
        _label_1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 100, 40)];
        _label_1.text = @"用户";
        _label_1.backgroundColor = [UIColor cyanColor];
    }
    return _label_1;
}

- (UILabel *)label_2{
    if (!_label_2) {
        _label_2 = [[UILabel alloc] initWithFrame:CGRectMake(50, 260, 100, 40)];
        _label_2.text = @"密码";
        _label_2.backgroundColor = [UIColor cyanColor];
    }
    return _label_2;
}

- (UITextField *)textfield_1{
    if (!_textfield_1) {
        _textfield_1 = [[UITextField alloc] initWithFrame:CGRectMake(170, 200, 150, 40)];
        _textfield_1.placeholder = @"请输入用户名";
        _textfield_1.backgroundColor = [UIColor cyanColor];
    }
    return _textfield_1;
}

- (UITextField *)textfield_2{
    if (!_textfield_2) {
        _textfield_2 = [[UITextField alloc] initWithFrame:CGRectMake(170, 260, 150, 40)];
        _textfield_2.placeholder = @"请输入密码";
        _textfield_2.backgroundColor = [UIColor cyanColor];
    }
    return _textfield_2;
}

- (UIButton *)button_1{
    if (!_button_1) {
       _button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
    [_button_1 setFrame:CGRectMake(75,330, 100, 50)];
    [_button_1 setTitle:@"登录" forState: UIControlStateNormal];
    [_button_1 addTarget:self action:@selector(loginAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button_1;
}
- (UIButton *)button_2{
    if (!_button_2) {
        _button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
        [_button_2 setFrame:CGRectMake(150,330, 100, 50)];
        [_button_2 setTitle:@"注册" forState: UIControlStateNormal];
        [_button_2 addTarget:self action:@selector(RegisterAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button_2;
}
  • RegisterAction:方法的回调(注册界面的)
- (void)RegisterAction:(UIButton *)button{
//进入注册页面
    RegisterViewController *registerVC = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerVC animated:YES];
}
#pragma mark-------在注册过程中,让用户感知到正在注册
- (UIActivityIndicatorView *)activityIndicatorView{
    if (!_activityIndicatorView) {
        _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        _activityIndicatorView.center = self.view.center;
        _activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
        _activityIndicatorView.color = [UIColor redColor];
        //直接添加在页面上的话.
        [self.view addSubview:_activityIndicatorView];
        
    }
    return _activityIndicatorView;
}

#pragma mark------提示框;
- (void)myAlerMessage:(NSString*)msg{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"友情提示" message: msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style: UIAlertActionStyleCancel handler:nil];
    [alertController addAction:sureAction];
    [self presentViewController:alertController animated:YES completion:nil];
}
#pragma mark------非空判断
- (BOOL)isSucces{
    if (self.textfield_1.text.length == 0) {
        [self myAlerMessage:@"用户名不能为空"];
        return NO;
    }
    if (self.textfield_2.text.length == 0) {
        [self myAlerMessage:@"密码不能为空"];
        return NO;
    }
    return YES;
}

相关文章

  • 建立管理钉钉群

    1,登陆钉钉app,点击“+”,选择“发起聊天” 2、点击“发起聊天”后,进入以下界面,选择对应群成员 3、群成员...

  • 聊天(3)---登陆界面

    登录界面 简单界面 1:导入头文件 2:声明需要构建页面的属性 为了确保使用的登录界面是同一个界面,使用单例 Re...

  • 登录界面

    一.登陆界面、 (1).开始界面 (2).输入界面密码成功时 (3).输入界面密码失败时 二. 登陆界面各控件的参...

  • 2018-10-11登陆界面设计 倪婉钰

    1、登陆界面效果图 2、登陆界面实现的功能 3、登陆界面控件参数设置 ①Label控件 ②comboBox控件 ③...

  • 超市管理系统界面设计

    1,登陆界面效果 2,登陆界面实现的功能 管理人员和收银人员分类进行系统登陆 3,登陆界面控件 4,重要方法描述 ...

  • 商超登陆界面设计

    一.界面图 二.登陆界面功能 1、登陆界面出现在屏幕正中央,并不可被放大或缩小。2、支持收银员合库管员登陆。3、输...

  • 青岛海尔智慧家庭——3D云设计—①创建户型

    首先登陆3D云设计网址:3d.haier.net 大家可以进行微信扫码登陆的方式(扫码之后云设计界面会自动跳转界面...

  • 智慧商超管理系统

    1. 登录界面的效果图 2. 登录界面实现的功能描述 1.库管员登陆、收银员登陆 登陆正确,显示成功 3.登录失败...

  • 商超登录界面

    1. 登陆界面效果图: 2.登录界面实现的功能描述: (1)收银员或库管员登陆商超管理系统。 3. 登录界面各控件...

  • 智能商超管理系统登陆界面设计

    一. 登陆界面的效果图 (1)开始界面登陆界面.png (2)用户类型选择界面用户类型选择.png 二. 登陆界面...

网友评论

      本文标题:聊天(3)---登陆界面

      本文链接:https://www.haomeiwen.com/subject/lrmjrttx.html