ios 实现注册 登录功能

//RegViewController.m


#import "RegViewController.h"

#import "LogViewController.h"

@interface RegViewController ()

@end

@implementation RegViewController
@synthesize userName;
@synthesize userPassword;
@synthesize userPasswordSecond;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [super viewDidLoad];
    self.title = @"注  册";
    UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    titleButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
    [titleButton setTitle:self.title forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    titleButton.frame = CGRectMake(0, 0, 150, 40);
    self.navigationItem.titleView = titleButton;
}

- (void)viewDidUnload
{
    [self setUserName:nil];
    [self setUserPassword:nil];
    [self setUserPasswordSecond:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [userName release];
    [userPassword release];
    [userPasswordSecond release];
    [super dealloc];
}
- (IBAction)btnReset:(id)sender {
    self.userName.text = @"";
    self.userPassword.text = @"";
    self.userPasswordSecond.text = @"";
}
- (IBAction)btnSubmit:(id)sender {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:userPassword.text forKey:@"PASSWORD"];
    [userDefault setObject:userName.text forKey:@"NAME"];
    [userDefault synchronize];
    
    
    LogViewController *registerView=[[LogViewController alloc]initWithNibName:@"LogViewController" bundle:nil];
    //            registerView.modalPresentationStyle=2;
    [self.navigationController pushViewController:registerView animated:YES];
}

- (IBAction)bgGround:(id)sender {
    [userName resignFirstResponder];//
    [userPassword resignFirstResponder];
    [userPasswordSecond resignFirstResponder];//

}
@end



LogViewController.m


#import "LogViewController.h"
#import "RegViewController.h"
#import "DisasterViewController.h"

@interface LogViewController ()

@end

@implementation LogViewController
@synthesize userName;
@synthesize userPassword;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString* pwd = [defaults stringForKey:@"PASSWORD"];
    NSString* name = [defaults stringForKey:@"NAME"];
    if(name&&pwd){
        self.userName.text = name;
        self.userPassword.text = pwd;
    }
    self.navigationItem.hidesBackButton = YES;
    self.title = @"登  陆";
    UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    titleButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
    [titleButton setTitle:self.title forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    titleButton.frame = CGRectMake(0, 0, 150, 40);
    self.navigationItem.titleView = titleButton;
}

- (void)viewDidUnload
{
    [self setUserName:nil];
    [self setUserPassword:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [userName release];
    [userPassword release];
    [super dealloc];
}
- (IBAction)btnRegister:(id)sender {
    
    RegViewController* registerView=[[RegViewController alloc]initWithNibName:@"RegViewController" bundle:nil];
    registerView.modalPresentationStyle=2;
    [self.navigationController pushViewController:registerView animated:YES];
    
    
}

- (IBAction)btnLogin:(id)sender {
    NSString *userName1 = self.userName.text;
    NSString *password1 = self.userPassword.text;
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString* pwd = [defaults objectForKey:@"PASSWORD"];
    NSString* name = [defaults objectForKey:@"NAME"];
    //表单提交前的验证
    if([name isEqualToString:userName1] && [pwd isEqualToString:password1] ){
                self.tabBarController.selectedIndex = 0;
                self.hidesBottomBarWhenPushed = NO;
                [self.navigationController popViewControllerAnimated:YES];
        
                DisasterViewController* registerView=[[[DisasterViewController alloc]initWithNibName:@"DisasterViewController" bundle:nil]autorelease ];
                registerView.modalPresentationStyle=2;
                registerView.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:registerView animated:NO];
        
        
    }else{
        self.view.frame=CGRectMake(0, 0, 320, 460);
        [userName resignFirstResponder];
        UIAlertView* alert = [[[UIAlertView alloc]initWithTitle:@"" message:@"账号密码出错" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] autorelease];
        [alert show];
        
    }

}

- (IBAction)bgGround:(id)sender {
    
    [userName resignFirstResponder];
    [userPassword resignFirstResponder];
}
@end

mainViewController.m


- (void)viewDidLoad
{
    [super viewDidLoad];
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    NSString* pwd = [defaults stringForKey:@"PASSWORD"];
    NSString* name = [defaults stringForKey:@"NAME"];
    if(!name && !pwd){
        shouldLoad = YES;
        LogViewController *view1=[[[LogViewController alloc]initWithNibName:@"LogViewController" bundle:nil] autorelease];
        view1.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:view1 animated:YES];
    }
    
    UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    titleButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
    [titleButton setTitle:@"主  页" forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    titleButton.frame = CGRectMake(0, 0, 150, 40);
    self.navigationItem.titleView = titleButton;
    
        NSString *str = [name stringByAppendingString:@"welcome to App"];
    self.labelWelcome.text = str;
}



DisasterViewController.m


-(void)viewDidLoad{
    BOOL isExistenceNetwork = YES;
        MainViewController *mainView = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
    UINavigationController *mainv = [[UINavigationController alloc]initWithRootViewController:mainView];
    [mainv.navigationBar setBackgroundImage:[UIImage imageNamed:@"ImageNavBg.png"] forBarMetrics:UIBarMetricsDefault];
        
    NSArray *array = [NSArray arrayWithObjects:mainv,  nil];
    
    UITabBarItem *indexTabBar = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"tabbar_home.png"] tag:101];
    mainv.tabBarItem = indexTabBar;
    [indexTabBar release];
    
       
    UITabBarController *tabBarController = [[[UITabBarController alloc]init] autorelease];
    tabBarController.tabBar.frame = CGRectMake(0, 436, 320, 44);
    tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_background.png"];
    tabBarController.viewControllers = array;
    [self presentModalViewController:tabBarController animated:YES];
    [mainv release];
    [mainView release];

}

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值