用导航控制器制作一个简单的登陆显示
1.Empty项目的创建+AppDelegate的修改
#import "DXWAppDelegate.h" #import "LoginViewController.h" @implementation DXWAppDelegate - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; //创建首页 LoginViewController *first = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; //创建一个导航栏,其中的首页是FirstViewController UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:first]; //将导航栏作为根视图控制器 self.window.rootViewController = nav; [first release]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
2.登陆视图的制作,命名为LoginViewController,带有xib文件
LoginViewController.h:
#import <UIKit/UIKit.h> @interface LoginViewController : UIViewController @property (retain, nonatomic) IBOutlet UITextField *ttbName; @property (retain, nonatomic) IBOutlet UITextField *ttbPassword; - (IBAction)ttbLogin:(id)sender; - (IBAction)ttbCancel:(id)sender; - (IBAction)resign:(id)sender; @end
LoginViewController.m:
#import "LoginViewController.h" #import "ReturnViewController.h" @interface LoginViewController () @end @implementation LoginViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // [self.navigationController setNavigationBarHidden:YES animated:YES]; } return self; } -(void)viewWillAppear:(BOOL)animated { self.ttbName.text = @""; self.ttbPassword.text = @""; [self.navigationController setNavigationBarHidden:YES animated:YES]; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [_ttbName release]; [_ttbPassword release]; [super dealloc]; } - (IBAction)ttbLogin:(id)sender { [self.ttbName resignFirstResponder]; [self.ttbPassword resignFirstResponder]; ReturnViewController *sec = [[ReturnViewController alloc] initWithNibName:@"ReturnViewController" bundle:nil]; sec.name = self.ttbName.text; sec.password = self.ttbPassword.text; [self.navigationController pushViewController:sec animated:YES]; } - (IBAction)ttbCancel:(id)sender { [self.ttbName resignFirstResponder]; [self.ttbPassword resignFirstResponder]; self.ttbPassword.text = @""; self.ttbName.text = @""; } - (IBAction)resign:(id)sender { [self.ttbName resignFirstResponder]; [self.ttbPassword resignFirstResponder]; } @end
3.创建详细信息显示视图,命名为ReturnViewController,带有xib文件
ReturnViewController.h:
#import <UIKit/UIKit.h> @interface ReturnViewController : UIViewController @property (retain, nonatomic) IBOutlet UILabel *lblName; @property (retain, nonatomic) IBOutlet UILabel *lblPassword; @property(copy,nonatomic)NSString *name; @property(copy,nonatomic)NSString *password; - (IBAction)return:(id)sender; @end
ReturnViewController.m:
#import "ReturnViewController.h" @interface ReturnViewController () @end @implementation ReturnViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void)viewWillAppear:(BOOL)animated { //隐藏导航栏 [self.navigationController setNavigationBarHidden:YES animated:YES]; // UIImage *imge = [UIImage imageNamed:@"psu.gif"]; // self.img = [[UIImageView alloc] initWithImage:imge]; self.lblName.text = self.name; self.lblPassword.text = self.password; } - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"psu.gif"]; UIImageView *picView = [[UIImageView alloc] initWithImage:image]; [self.view insertSubview:picView atIndex:13]; picView.frame = CGRectMake(92, 161, 136, 115); } - (void)dealloc { [_lblName release]; [_lblPassword release]; [super dealloc]; } - (IBAction)return:(id)sender { [self.navigationController popToRootViewControllerAnimated:YES]; } @end
项目源码:http://download.csdn.net/detail/s10141303/5991219
本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366425
,如需转载请自行联系原作者