Chinaunix首页 | 论坛 | 博客
  • 博客访问: 90994
  • 博文数量: 22
  • 博客积分: 486
  • 博客等级: 下士
  • 技术积分: 262
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-07 19:26
文章分类

全部博文(22)

文章存档

2012年(22)

我的朋友

分类: 嵌入式

2012-07-05 16:42:51



点击(此处)折叠或打开

  1. - (void)viewDidLoad
  2. {
  3.     [super viewDidLoad];
  4.  //加载窗口的时候把从文件里读出用户名。
  5.  NSString *filePath = [self documentsPath:@"user.txt"];
  6.     //读出文件存到数组username中
  7.     NSArray *username = [NSArray arrayWithContentsOfFile:filePath];
  8.     self.TXF1.text = [username objectAtIndex:0];
  9.     self.Txtpwd.text = [username objectAtIndex:1];
  10.     //文本显示设为安全。星号
  11.     self.Txtpwd.secureTextEntry = YES;
  12. }

  13. //登陆验证
  14. - (IBAction)loginpage:(id)sender
  15. {
  16.     NSLog(@"login...\n");
  17.     NSString *filePath = [self documentsPath:@"user.txt"];
  18.     //从user这个文件里读出用户名和密码是否与输入的相同
  19.     NSArray *username = [NSArray arrayWithContentsOfFile:filePath];
  20.     if([TXF1.text isEqualToString:[username objectAtIndex:0]] && [Txtpwd.text isEqualToString:[username objectAtIndex:1]])
  21.     {
  22. //如果验证正确,则重新打开一个窗口
  23.         if(self.loginhome ==nil)
  24.         {
  25.             NSLog(@"loginhome");
  26.             loginhome *homepage = [[loginhome alloc]initWithNibName:@"loginhome" bundle:nil];
  27.             self.loginhome = [homepage autorelease];
  28.             [self.view addSubview:self.loginhome.view];
  29.         }
  30.         else
  31.         {
  32.             [self.view addSubview:self.loginhome.view];
  33.         }

  34.         NSLog(@"登陆成功!\n");
  35.         
  36.     }
  37.     else
  38.     {
  39.         NSLog(@"用户名或密码错误!\n");
  40.         judgelogin = [[UIAlertView alloc]initWithTitle:@"提示"
  41.                                              message:@"用户名或密码错误!"
  42.                                             delegate:self
  43.                                    cancelButtonTitle:@"取消"
  44.                                    otherButtonTitles:@"确定",nil];
  45.         [judgelogin show];
  46.         [judgelogin release];
  47.      
  48.     }
  49.     
  50. }


  51. //读程序目录而准备
  52. -(NSString *)bundlePath:(NSString *)fileName {
  53.     return [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName];
  54. }

  55. -(NSString *)documentsPath:(NSString *)fileName {
  56.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  57.     NSString *documentsDirectory = [paths objectAtIndex:0];
  58.     return [documentsDirectory stringByAppendingPathComponent:fileName];
  59. }

  60. -(NSString *)documentsPath {
  61.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  62.     NSString *documentsDirectory = [paths objectAtIndex:0];
  63.     return documentsDirectory;
  64. }

阅读(2966) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~