iPhone 的.m文件解釋

//

//  MainViewController.m

//  textFieldExample

//

//  Created by KeyrunIOSX on 14-3-12.

//  Copyright (c) 2014 KeyrunIOSX. All rights reserved.

//


#import "MainViewController.h"


@interface MainViewController ()


@end


@implementation MainViewController

@synthesize name;

@synthesize pwd;

//通過xid文件名字來初始化視圖

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


//加載完成之後將調用

- (void)viewDidLoad

{

    [super viewDidLoad];

    //制定文本框打代理  這一步很重要

    name.delegate=self;

    pwd.delegate=self;

    [name becomeFirstResponder];

    NSLog(@"did load");

    //[name becomeFirstResponder];

    // Do any additional setup after loading the view from its nib.

}


//視圖卸載的時候將調用   (是一個過時的方法)

-(void)viewDidUnload{

    

    self.name=nil;

    self.pwd=nil;

    [super viewDidUnload];

}


//內存警告方法,一般不用!有內存方面問題應該尋找其他的解決方法

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


//登錄  自定義事件

- (IBAction)Login:(UIButton *)sender {

    NSLog(@"用戶名:,密碼");

}


//重寫了textfielddelegate的方法

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{

    return YES;

}


//重寫該方法  點擊return時隱藏小鍵盤

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    NSLog(@"shouldReturn");

    BOOL temp =[name resignFirstResponder];

    NSLog(@"測試%@",temp?@"YES":@"NO");

    [pwd resignFirstResponder];

    return YES;

}


//點擊view其他區域隱藏鍵盤

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"touchesBegan");

    [name becomeFirstResponder];

    [name resignFirstResponder];

    [pwd resignFirstResponder];

}


//軟鍵盤控制方法

-(BOOL)disablesAutomaticKeyboardDismissal{

    return NO;

}


//設置橫屏等調用時調用

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{

    return YES;

}


//釋放內存

-(void)dealloc{

    [name release];

    [pwd release];

    [super dealloc];

}

@end


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章