Iphone-use TextField and the useing TextField for inputs, using th

Source: Internet
Author: User

Create a project named KeyBoard. I use xcode4.2!
Drag four labels and four textfields in the MainStoryboard. storyboard file, as shown in the following figure:

Filled content:
The Done keyboard disappears !!
First, let's talk about the following attributes of the four textfields:
Name:

Age: keyboard changed to Numbers and Punctuation
Password: link the Secure attribute to www.2cto.com
Email: keyBoard sent to email Address
The KeyboardViewController. h file is defined as follows:
 

<Span style = "font-size: 16px;">-(IBAction) doneEdit :( id) sender; </span>
<Span style = "font-size: 16px;">-(IBAction) doneEdit :( id) sender; </span> the KeyboardViewController. m file is implemented as follows:


[Html] <span style = "font-size: 16px;">-(IBAction) doneEdit :( id) sender {
[Sender resignFirstResponder];
} </Span>
<Span style = "font-size: 16px;">-(IBAction) doneEdit :( id) sender {
[Sender resignFirstResponder];
} </Span>
Connect the four TextFiled Did End on Exit to the egress IBAction and connect to the doneEdit method! Everyone knows how to connect! No legend is provided here!
[Sender resignFirstResponder] is to require the resignation of the first responder of a text field. This means that the interaction between the keyboard and text fields is no longer needed to hide it!

In this way, some people will think: "I don't want to press the Done key to hide it. I want it to press the background behind it to hide the keyboard .", Don't worry. Next let's talk about this situation !!!!

Also in the original project, add a button in the view, a large button to cover the front view, and change the Type attribute to Custom, and pull the button to the top of all controls, that is, the first position, as shown in the following code, to prevent the button from blocking all buttons!

 

 

Add the following code to the KeyboardViewController. h file:


[Cpp] @ interface KeyboardViewController: UIViewController {
UITextField * email;
UITextField * password;
UITextField * age;
UITextField * name;
}
@ Property (retain, nonatomic) IBOutlet UITextField * email;
@ Property (retain, nonatomic) IBOutlet UITextField * password;
@ Property (retain, nonatomic) IBOutlet UITextField * age;
@ Property (retain, nonatomic) IBOutlet UITextField * name;
-(IBAction) buttonEdit :( id) sender;
-(IBAction) doneEdit :( id) sender;
@ End
@ Interface KeyboardViewController: UIViewController {
UITextField * email;
UITextField * password;
UITextField * age;
UITextField * name;
}
@ Property (retain, nonatomic) IBOutlet UITextField * email;
@ Property (retain, nonatomic) IBOutlet UITextField * password;
@ Property (retain, nonatomic) IBOutlet UITextField * age;
@ Property (retain, nonatomic) IBOutlet UITextField * name;
-(IBAction) buttonEdit :( id) sender;
-(IBAction) doneEdit :( id) sender;
@ End
Connect the button Touch Up Inside Event to buttonEdit;

In the KeyboardViewController. m file:


[Cpp] @ synthesize email;
@ Synthesize password;
@ Synthesize age;
@ Synthesize name;
-(IBAction) buttonEdit :( id) sender {
[Email resignFirstResponder];
[Password resignFirstResponder];
[Age resignFirstResponder];
[Name resignFirstResponder];
}
@ Synthesize email;
@ Synthesize password;
@ Synthesize age;
@ Synthesize name;
-(IBAction) buttonEdit :( id) sender {
[Email resignFirstResponder];
[Password resignFirstResponder];
[Age resignFirstResponder];
[Name resignFirstResponder];
}

In this way, you can click back to close the keyboard.

Someone may think: "I want to open the application and open the keyboard and the cursor is in the name box ".

Write the code in viewDidLoad:


[Cpp]-(void) viewDidLoad
{
[Name becomeFirstResponder];
[Super viewDidLoad];
}
-(Void) viewDidLoad
{
[Name becomeFirstResponder];
[Super viewDidLoad];
}
Well!


I am not afraid of trouble during the learning process. I hope to study hard with you! What's wrong? Please point out more !!!

 

From Ren haili (3G/mobile development)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.