博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用导航控制器制作一个简单的登陆显示
阅读量:6350 次
发布时间:2019-06-22

本文共 4516 字,大约阅读时间需要 15 分钟。

用导航控制器制作一个简单的登陆显示

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 
@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 
@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
,如需转载请自行联系原作者
你可能感兴趣的文章
磁盘显示无法访问拒绝访问,里面的资料怎样找到
查看>>
Java之品优购课程讲义_day07(5)
查看>>
Java的新项目学成在线笔记-day3(八)
查看>>
路由简单的实验
查看>>
Centos6.4 xen编译部署
查看>>
好程序员web前端教程分享js reduce方法使用教程
查看>>
零基础学习大数据Hadoop需要什么准备?Hadoop如何发展起来的?
查看>>
前端程序员需要具备的几个软实力,你具备了吗
查看>>
RHEL系列网络配置2015083101
查看>>
c# 基本值类型及其默认值
查看>>
服务器端解决JS跨域调用问题
查看>>
迁移至个人blog
查看>>
MySql中添加用户,新建数据库,用户授权,删除用户,修改密码
查看>>
雨巷-戴望舒
查看>>
OpenCms创建网站过程图解——献给OpenCms的初学者们
查看>>
C++ 异常处理机制的实现
查看>>
Freebsd的ports命令
查看>>
分布式系统---幂等性设计
查看>>
【转】时钟周期,机器周期,指令周期的区别
查看>>
MYSQL 更新时间自己主动同步与创建时间默认值共存问题
查看>>