欢迎来到天天文库
浏览记录
ID:59364613
大小:16.00 KB
页数:2页
时间:2020-09-04
《用户名和密码登陆界面的代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、-(void)viewDidLoad{[superviewDidLoad];//加载窗口的时候把从文件里读出用户名。NSString*filePath=[selfdocumentsPath:@"user.txt"];//读出文件存到数组username中NSArray*username=[NSArrayarrayWithContentsOfFile:filePath];self.TXF1.text=[usernameobjectAtIndex:0];self.Txtpwd.text=[usernameobjectAtIndex:1];//
2、文本显示设为安全。星号self.Txtpwd.secureTextEntry=YES;}//登陆验证-(IBAction)loginpage:(id)sender{NSLog(@"login...");NSString*filePath=[selfdocumentsPath:@"user.txt"];//从user这个文件里读出用户名和密码是否与输入的相同NSArray*username=[NSArrayarrayWithContentsOfFile:filePath];if([TXF1.textisEqualToString:[us
3、ernameobjectAtIndex:0]]&&[Txtpwd.textisEqualToString:[usernameobjectAtIndex:1]]){//如果验证正确,则重新打开一个窗口if(self.loginhome==nil){NSLog(@"loginhome");loginhome*homepage=[[loginhomealloc]initWithNibName:@"loginhome"bundle:nil];self.loginhome=[homepageautorelease];[self.viewaddSub
4、view:self.loginhome.view];}else{[self.viewaddSubview:self.loginhome.view];}NSLog(@"登陆成功!");}else{NSLog(@"用户名或密码错误!");judgelogin=[[UIAlertViewalloc]initWithTitle:@"提示"message:@"用户名或密码错误!"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];[judgeloginshow];
5、[judgeloginrelease];}}//读程序目录而准备-(NSString*)bundlePath:(NSString*)fileName{return[[[NSBundlemainBundle]bundlePath]stringByAppendingPathComponent:fileName];}-(NSString*)documentsPath:(NSString*)fileName{NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
6、NSUserDomainMask,YES);NSString*documentsDirectory=[pathsobjectAtIndex:0];return[documentsDirectorystringByAppendingPathComponent:fileName];}-(NSString*)documentsPath{NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString*docum
7、entsDirectory=[pathsobjectAtIndex:0];returndocumentsDirectory;}
此文档下载收益归作者所有