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

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

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值