This tutorial will show you how to make a basic application for the iPhone which will present two text boxes with a keyboard which will slide up when the text box is active.
Step one
Create a new view based application and called it tut2.
Step Two
Go to tut2ViewController.h and add
UITextField *username;
UITextField *password;
}
@property(retain, nonatomic) IBOutlet UITextField *username;
@property(retain, nonatomic) IBOutlet UITextField *password;
Step Three
Once done, go to tut2ViewController.m and add
@synthesize username;
@synthesize password;
and inside -(void) dealloc add:
[username release];
[password release];
Step Four
Save and click on Build to ensure there are no errors, if there are back track through the above steps.Step Five
Click on tut2ViewController.xib to open up the interface builder. Once open, add two text boxes and two labels. Call one label username and another password.
Step Six
Now click on the username text box, go to the inspector and type in enter username into the placeholder. Then go down the window to Text Input Traits and change the return key box to done.
Step Seven
Then click on the password text box, and change the placeholder to enter password. Go to Text Input Traits and click on the keyboard box and change it to Number Pad, then click on the secure check box.Step Eight
Next link the text boxes to the Files owner by holding Ctrl and dragging a line from files owner, when you let go click on username for the username input box and for the password input box click on password.Step Nine
Go back to tut2ViewController.h and add
-(IBAction) closeKeyboard: (id) sender;
-(IBAction) outsideClose: (id) sender;
Then go to tut2ViewController.m and add
- (IBAction) closeKeyboard: (id) sender{
[sender resignFirstResponder];
}
-(IBAction) outsideClose: (id) sender{
[name resignFirstReponder];
[password resignFirstResponder];
}
Step Ten
Once done click on save and go back to the interface builder. Click on the username input box, go to the connections window and drag "Did End on Exit" to the files owner and select closeKeyboard, Then click on the view in the small window, then click on Tools -> Identity Inspector. Change the class to UIControl. Next, go to the connections and link the Touch Down to the files owner and click on outsideClose.