简单的页面登陆和页面跳转

[size=x-large]首先做出一个登陆的基本页面[/size]
[img]http://dl.iteye.com/upload/attachment/347002/a731a023-60ea-3c09-9ac9-5be99813e39b.png[/img]
[size=x-large]在.h文件中写出所用到的接口和方法[/size]

@interface _1_11LoginViewController : UIViewController {
IBOutlet UITextField *namefield;
IBOutlet UITextField *passwordfield;
}
@property (nonatomic,retain) UITextField *namefield;
@property (nonatomic,retain) UITextField *passwordfield;
@property (nonatomic,retain) UIButton *allowButton;
-(IBAction)login;
-(IBAction)namefieldEditing:(id)sender;
-(IBAction)changeTextFile;
-(IBAction)doneLogin;
-(IBAction)allow;
@end


[size=x-large]首先关注一下textfield中按钮的控制,[/size]
[img]http://dl.iteye.com/upload/attachment/347022/972e5acd-336d-3b3a-90af-e0cc9834d47f.png[/img]

[size=x-large]如果想在输入name完成是自动跳转到password的输入则进行以下设置:
选中上面的textfield框,在interface bulider中找到return key属性设置,将其改为next,那么原输入框右下角的Done会变为Next。[/size]
[img]http://dl.iteye.com/upload/attachment/347024/41489bdd-bb9a-39cc-8d29-f8db8bcb07ea.png[/img]
[size=x-large]这是他的实现方法[/size]
-(IBAction)changeTextFile
{
[passwordfield becomeFirstResponder];

}

[size=x-large]而在下面的textfield设置是记将secure选项选中,即当输入密码时会用*代替[/size]
[img]http://dl.iteye.com/upload/attachment/347028/c20a13b5-8851-3a59-a239-54dcda000225.png[/img]

[size=x-large]下面就是要进行页面跳转的工作了,在file菜单下选择new file选项,再选择UIviewController,顺便选中下面的生成xib文件的选项,点击next,取名successLogin,生成文件后将.xib拖入resources文件夹中,再实现以下代码[/size]

#import "successLogin.h"

-(IBAction)doneLogin{
successLogin *mysuccessLogin = [[successLogin alloc] initWithNibName:@"successLogin" bundle:nil];
[self.view.window addSubview:mysuccessLogin.view];
[mysuccessLogin release];
}
}

[size=x-large]这样就可以实现跳转了,但是我们一般对输入内容都有一定的限制,比如内容要大于4位,若小于四位则弹出对话框进行提示[/size]

[img]http://dl.iteye.com/upload/attachment/347049/ddf46ca9-2c5a-32fb-b01f-aecd6e1657a2.png[/img]
实现下面代码:
-(IBAction)login{
if (namefield.text.length<4||passwordfield.text.length<4) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wrong"
message:@"They are not long enough"
delegate:self
cancelButtonTitle:@"I konw"
otherButtonTitles:nil];
[alert show];
[alert release];
}else {
successLogin *mysuccessLogin = [[successLogin alloc] initWithNibName:@"successLogin" bundle:nil];
[self.view.window addSubview:mysuccessLogin.view];
[mysuccessLogin release];
}
}


[size=x-large]这样一个简单的页面就完成了。[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值