使用LeanCloud注册功能让邮箱在界面可选的方法
来源:互联网 发布:iptv机顶盒安装软件 编辑:程序博客网 时间:2024/05/17 23:41
使用LeanCloud做注册功能时,可以只用用户名和密码注册,也可以用户名,密码,邮箱一起注册。如果你在注册方法里加了邮箱的( user.email = _email.text;),那么你不填邮箱是不能成功注册的。如果想把邮箱做成可选可以看下我的方法,写一个BOOL属性,设置初始值为NO,在TextField的监听方法(-(void)textFieldDidChange :(UITextField *)theTextField)里面,当邮箱输入大于0个字符时,将BOOL属性赋值为YES,再在注册的点击方法里面这样
if (_emailJudge == YES) {
user.email = _email.text;
}
写。就可以达到输不输邮箱都能注册成功的目的。
效果图如下
具体代码如下 :
// Copyright © 2016年 RanFeiHong. All rights reserved.
//
#import "Registered.h"
#import <AVOSCloud/AVOSCloud.h>
#import "Login.h"
@interface Registered ()
@property (nonatomic,strong) UITextField *username;
@property (nonatomic,strong) UITextField *password;
@property (nonatomic,strong) UITextField *email;
@property (nonatomic,strong) UIButton *logon;
@property (nonatomic,assign) BOOL emailJudge;
@end
@implementation Registered
- (void)viewDidLoad {
[superviewDidLoad];
_emailJudge =NO;
self.view.backgroundColor = [UIColorcolorWithRed:231/255.0green:244/255.0blue:242/255.0alpha:1];
UIButton *back = [UIButtonbuttonWithType:UIButtonTypeCustom];
back.frame =CGRectMake(15,30, 30,30);
[back setImage:[UIImageimageNamed:@"登录注册返回.jpg"]forState:UIControlStateNormal];
[back addTarget:selfaction:@selector(backAction)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:back];
_logon = [UIButtonbuttonWithType:UIButtonTypeSystem];
_logon.frame =CGRectMake(30,370, 315,60);
_logon.backgroundColor = [UIColorcolorWithRed:203/255.0green:166 /255.0 blue:225 /255.0 alpha:1];
[_logonsetTitleColor:[UIColorcolorWithRed:118 /255.0 green:135 /255.0 blue:138 /255.0 alpha:1]forState:UIControlStateHighlighted];
[_logonsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[_logonsetTitle:@"注册"forState:UIControlStateNormal];
_logon.userInteractionEnabled =NO;
_logon.alpha =0.5;
_logon.layer.cornerRadius =28;
_logon.layer.masksToBounds =YES;
[_logonaddTarget:selfaction:@selector(zhuche)forControlEvents:UIControlEventTouchUpInside];
_logon.titleLabel.font = [UIFont systemFontOfSize:23];
[self.viewaddSubview:_logon];
_username = [[UITextFieldalloc] initWithFrame:CGRectMake(80, 100, 265,50)];
_username.placeholder =@"请输入要注册的账号";
[_usernameaddTarget:selfaction:@selector(textFieldDidChange:)forControlEvents:UIControlEventEditingChanged];
[self.viewaddSubview:_username];
_password = [[UITextFieldalloc] initWithFrame:CGRectMake(80, 180, 265,50)];
_password.placeholder =@"请输入密码";
[_passwordaddTarget:selfaction:@selector(textFieldDidChange:)forControlEvents:UIControlEventEditingChanged];
[self.viewaddSubview:_password];
_email = [[UITextFieldalloc] initWithFrame:CGRectMake(80, 260, 265,50)];
_email.placeholder =@"请输入邮箱(可选)";
[self.viewaddSubview:_email];
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(30,100, 48,50)];
label.text =@"账号";
label.font = [UIFontsystemFontOfSize:18];
label.textColor = [UIColorblackColor];
[self.viewaddSubview:label];
UILabel *label3 = [[UILabelalloc]initWithFrame:CGRectMake(30,180, 48,50)];
label3.text =@"密码";
label3.font = [UIFontsystemFontOfSize:18];
label3.textColor = [UIColorblackColor];
[self.viewaddSubview:label3];
UILabel *label2 = [[UILabelalloc]initWithFrame:CGRectMake(30,260, 48,50)];
label2.text =@"邮箱";
label2.font = [UIFontsystemFontOfSize:18];
label2.textColor = [UIColorblackColor];
[self.viewaddSubview:label2];
//
UIView *line = [[UIViewalloc]initWithFrame:CGRectMake(30,160, 310,1)];
line.backgroundColor = [UIColorblackColor];
[self.viewaddSubview:line];
UIView *line2 = [[UIViewalloc]initWithFrame:CGRectMake(30,240, 310,1)];
line2.backgroundColor = [UIColorblackColor];
[self.viewaddSubview:line2];
UIView *line3 = [[UIViewalloc]initWithFrame:CGRectMake(30,320, 310,1)];
line3.backgroundColor = [UIColorblackColor];
[self.viewaddSubview:line3];
}
- (void)zhuche
{
AVUser *user = [AVUseruser];
user.username =_username.text;
user.password = _password.text;
if (_emailJudge ==YES) {
user.email =_email.text;
}
[user signUpInBackgroundWithBlock:^(BOOL succeeded,NSError *error) {
if (succeeded) {
Login *dv = [[Loginalloc] init];
[self.navigationControllerpushViewController:dv animated:YES];
} else
{
// NSLog(@"%@",error.localizedDescription);
UIAlertController *alertVC = [UIAlertControlleralertControllerWithTitle:@"注册失败"message:error.localizedDescriptionpreferredStyle:UIAlertControllerStyleAlert];
[selfpresentViewController:alertVCanimated:YEScompletion:nil];
UIAlertAction *sureAct1 = [UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleCancelhandler:nil];
[alertVC addAction:sureAct1];
}
}];
}
- (void)backAction
{
[self.navigationControllerpopViewControllerAnimated:YES];
}
-(void)textFieldDidChange :(UITextField *)theTextField
{
if (_username.text.length > 0 && _password.text.length > 0 ) {
_logon.userInteractionEnabled =YES;
_logon.alpha =1;
}else
{
_logon.userInteractionEnabled =NO;
_logon.alpha =0.5;
}
if (_email.text.length > 0) {
_emailJudge =YES;
}else
{
_emailJudge =NO;
}
}
@end
做法很简单,有更好的做法欢迎大家指教。
- 使用LeanCloud注册功能让邮箱在界面可选的方法
- 用leancloud的登陆注册功能
- 关于LeanCloud做注册功能时验证短信不能发出的设置方法
- 邮箱注册界面(没有实现功能)
- 让网站禁止某些邮箱的注册
- 使用leancloud实现登录注册,数据存储,即使通讯等功能
- 邮箱注册功能测试的测试点
- 注册邮箱激活功能
- 用户在注册成功后,发送用户名和密码到其注册邮箱的方法
- 让协议protocol中的方法在某个类中可选
- 软件测试-邮箱注册界面
- leancloud 使用的坑lists
- leanCloud使用的时候心得
- 使用LeanCloud的分页查询
- 日历类Calendar在注册界面的使用
- 邮箱注册新会员,以及邮箱激活功能
- 让input不可选的几种方法
- ECshop中注册时的邮箱验证功能实现代码
- 创新实验室第二周 解题报告
- 第五周项目一(8)选择结构和循环结构的第一次嵌套使用
- “掏肛”般逆袭:打通“家务事”最后5公里“宅神”社区有多神?
- [codevs1507] 酒厂选址
- TextAlign 与 margin:0 auto
- 使用LeanCloud注册功能让邮箱在界面可选的方法
- Android开发:详解Handler的内存泄露
- JDK1.8 十大新特性详解
- 在Activity中,layout布局中控件的各种实例化
- 数据库与表的操作之创建表(CREATE TABLE)
- 数值方法:多项式插值
- odata初探01
- 基于Opencv2.4.11+OpenGL(Qt5.6.0)实现增强现实(一)
- 第五周【项目二-建立链栈算法库】