2013年9月19日 星期四

【iOS筆記】輸入後,隱藏Keyboard

【iOS筆記】輸入後,隱藏Keyboard


Remarks

以鍵盤輸入時,鍵盤會顯示在最上層,而輸入後,鍵盤應隱藏,而將控制權交給其他控制項。

UI Design


 在 TextField 新增 Action x1 : hideKeyboard, 而由事件 Event: Did End On Exit 來觸發此 Action。

Run Result


輸入後,按鍵盤 Return 鍵,此鍵盤會隱藏。


Review


在MainStoryboard.storyboard圖示有個箭頭,顯示此View的First Responder,而當開始輸入時,鍵盤顯示在上層,而成為 First Responder,因此輸入完,應該以Resign First Responder 方式,將此鍵盤隱藏在後。

Source Code


//
//  EMViewController.h
//  HelloNoun
//
//  Created by Mac on 13/9/19.
//  Copyright (c) 2013年 Mac. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface EMViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *inputLabel;
@property (strong, nonatomic) IBOutlet UILabel *outputLabel;
- (IBAction)setLabel:(id)sender;
- (IBAction)hideKeyboard:(id)sender;


@end


//
//  EMViewController.m
//  HelloNoun
//
//  Created by Mac on 13/9/19.
//  Copyright (c) 2013年 Mac. All rights reserved.
//

#import "EMViewController.h"

@interface EMViewController ()

@end

@implementation EMViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)setLabel:(id)sender {
    self.outputLabel.text = self.inputLabel.text;
}

- (IBAction)hideKeyboard:(id)sender {
    [self.inputLabel resignFirstResponder];
}



@end




/end

沒有留言:

張貼留言

prettyPrint();