I am making a universal tabbed application, and one of the tabs is a login screen. How do I make the keyboard disappear when the user tabs outside the box or taps the sign in button? Also how do I link the next button to the password box as in when you type the username, there is a next button instead of a return button, but it won't go to the next field. I have tried other forums but they give me a stop sign (icon) error.
2. Use the textfield delegate method, something like textFieldDidReturn. Make the second UITextfield the first responder and relieve the first one of its duties.
Where would I place that code? All I did was add a textfield (as in the picture) from the toolbox, I didn't write it in code. Here is all the code (except for the green stuff at the top):
Make IBOutlets for the text fields. then hook them up in IB. While in IB set the tag's of the text fields to 0 and 1 (you only have 2 fields right?) Then implement the textFieldShouldReturn method. That can be placed anywhere inside the .m for that view controller you want - it is a new method unto itself and doesnt need "calling" from elsewhere. In the method set an int to the textfield.tag and add 1 to it. Then an if statement to check when it has reached the highest tag it should return YES;.
For dismissing the keyboard on a click (i.e. background click) create an IBAction (i call mine background click :P) and in that method call "resignFirstResponder" on each of the text fields.
Post back if you need that clearing up a bit, rather not spoon feed the code if you can figure it out
Last edited by Meredi86; 07-12-2011 at 10:17 AM.
Reason: changing a typo
Xcode 4 does have Interace Builder, it's just integrated into Xcode. IBOutlets are a way to reference objects built in Interface Builder. You declare them in your header file like so
Code:
IBOutlet UITextField *myTextField;
Then you go into Interface Builder, select the file owner, go to the last tab in properties, and click and drag the circle to the object.
I found out how to make the keyboard disappear when you tap outside, but how do I make the next button link to the password box and the done button on the keyboard make the keyboard dissappear? Code for dismissing the keyboard when tapping outside:
PHP Code:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIView* view in self.view.subviews)
{
if ([view isKindOfClass:[UITextField class]]) {
[view resignFirstResponder];
}
if ([view isKindOfClass:[UITextView class]]) {
[view resignFirstResponder];
}
}
}
I found out how to make the keyboard disappear when you tap outside, but how do I make the next button link to the password box and the done button on the keyboard make the keyboard dissappear? Code for dismissing the keyboard when tapping outside:
PHP Code:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIView* view in self.view.subviews)
{
if ([view isKindOfClass:[UITextField class]]) {
[view resignFirstResponder];
}
if ([view isKindOfClass:[UITextView class]]) {
[view resignFirstResponder];
}
}
}
Dismissing keyboard with done button:
Code:
//in viewdidload
//Field is an IBOutlet
Field.delegate = self;
Field.returnKeyType = UIReturnKeyDone;