`
hx.19890101
  • 浏览: 109127 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

    博客分类:
  • ios
阅读更多
首先做出一个登陆的基本页面

在.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];
	}
}


这样一个简单的页面就完成了。
  • 大小: 184.1 KB
  • 大小: 98.4 KB
  • 大小: 15.3 KB
  • 大小: 15.2 KB
  • 大小: 43.3 KB
  • 大小: 96.7 KB
2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics