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

简单的页面登陆和页面跳转
首先做出一个登陆的基本页面
简略的页面登陆和页面跳转
在.h文件中写出所用到的接口和方法

@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


首先关注一下textfield中按钮的控制,
简略的页面登陆和页面跳转

如果想在输入name完成是自动跳转到password的输入则进行以下设置:
选中上面的textfield框,在interface bulider中找到return key属性设置,将其改为next,那么原输入框右下角的Done会变为Next。

简略的页面登陆和页面跳转
这是他的实现方法
-(IBAction)changeTextFile
{
	[passwordfield becomeFirstResponder]; 

}

而在下面的textfield设置是记将secure选项选中,即当输入密码时会用*代替
简略的页面登陆和页面跳转

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

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

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

简略的页面登陆和页面跳转
实现下面代码:
-(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];
	}
}


这样一个简单的页面就完成了。