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

简介: 用导航控制器制作一个简单的登陆显示 1.Empty项目的创建+AppDelegate的修改 #import "DXWAppDelegate.h"#import "LoginViewController.

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

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



相关文章
|
4月前
|
小程序 定位技术 API
uniapp 开发微信小程序 --【地图】打开地图选择位置,打开地图显示位置(可开启导航)
uniapp 开发微信小程序 --【地图】打开地图选择位置,打开地图显示位置(可开启导航)
335 0
|
5月前
|
JavaScript
技术心得:根据不同访问设备跳转到PC页面或手机页面
技术心得:根据不同访问设备跳转到PC页面或手机页面
53 0
|
6月前
|
小程序
微信小程序实现不同按钮跳转同一个页面显示不同内容
微信小程序实现不同按钮跳转同一个页面显示不同内容
143 0
|
6月前
|
定位技术 iOS开发
iphone4s经过地图页面直接跳转到其它页面导致页面不能正常加载
iphone4s经过地图页面直接跳转到其它页面导致页面不能正常加载
34 0
|
12月前
|
小程序 JavaScript 定位技术
小程序点击指定地址按钮直接打开地图导航
小程序点击指定地址按钮直接打开地图导航
236 0
Discuz如何自主控制弹框的显示(2)
Discuz如何自主控制弹框的显示
126 0
Discuz如何自主控制弹框的显示(2)
|
前端开发 JavaScript
漏刻有时后台左侧菜单默认隐藏的解决方案
漏刻有时后台左侧菜单默认隐藏的解决方案
69 0
|
安全 Java 数据库
页面控制菜单的显示或隐藏|学习笔记
快速学习页面控制菜单的显示或隐藏
页面控制菜单的显示或隐藏|学习笔记
|
iOS开发
iOS开发 - 使用UISearchController跳转新控制器时搜索框依然出现
iOS开发 - 使用UISearchController跳转新控制器时搜索框依然出现
134 0
|
前端开发
前端工作总结259-uni--菜单页面
前端工作总结259-uni--菜单页面
77 0
前端工作总结259-uni--菜单页面