//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];
}