View Full Version : Help with my keyboard moving down!
trojanvillage
Aug 1, 2009, 07:29 PM
I need some help with the keyboard in my App. When you click the first textField, the keyboard pops up just fine, select the view or 'Done', the keyboard moves down. However, if I select the second textField while the first textField is selected and the keyboard is showing, the view moves up again! how do i correct this? The keyboards are different types too. The first is the default keyboard, the second is the Phone Pad.
I even made them two different entities, instead of sharing the textField designation to no avail.
Ideas?
Thanks a lot!
Wes
dejo
Aug 2, 2009, 11:23 PM
However, if I select the second textField, it moves up again!
It? You mean, the keyboard moves up again? You don't want the keyboard appearing for the second textField? Or do you mean you don't want the keyboard disappearing and then reappearing when moving between textFields. Sorry, I'm a little confused by what exactly the issue is. Can you show us your code for textFieldShouldReturn:?
trojanvillage
Aug 3, 2009, 07:00 AM
It? You mean, the keyboard moves up again? You don't want the keyboard appearing for the second textField? Or do you mean you don't want the keyboard disappearing and then reappearing when moving between textFields. Sorry, I'm a little confused by what exactly the issue is. Can you show us your code for textFieldShouldReturn:?
I might not be able to do the following. Instead of having one textFieldShouldReturn, can I split them up for the two different textFields?
- (BOOL)textFieldAddressShouldReturn: (UITextField *)textFieldAddress {
[textFieldAddress resignFirstResponder];
if (moveViewUp) [self scrollTheView:NO];
[self updateAddress];
return YES;
}
- (BOOL)textFieldPhoneNumberShouldReturn: (UITextField *)textFieldPhoneNumber {
[textFieldPhoneNumber resignFirstResponder];
if (moveViewUp) [self scrollTheView:NO];
[self updatePhoneNumber];
return YES;
}
dejo
Aug 3, 2009, 10:54 AM
I might not be able to do the following. Instead of having one textFieldShouldReturn, can I split them up for the two different textFields?
Not if they both have the same object set as their delegate. It's not a big deal having one delegate method anyways. Just check which textField is calling the textFieldShouldReturn method and handle appropriately. Something like this:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == textFieldAddress) {
// handle your address text field
} else if (textField == textFieldPhoneNumber) {
// handle your phone number text field
}
return YES;
}
P.S. This code snippet assumes that your have textFieldAddress and textFieldPhoneNumber set up and assigned eleswhere.
trojanvillage
Aug 3, 2009, 09:27 PM
that helped solve the problem (thanks!) of the Done button not working. I am still having a problem with the view moving up a second time when you jump from one text view directly to another. it gives me a problem with the userInfo part. I'm new to the iPhone SDK so if I'm doing something blatantly wrong, please be patient :)
here's where I think the problem is:
- (void)keyboardWillShow: (NSNotificationCenter *)notif {
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
float bottomPointA = (textFieldAddress.frame.origin.y+ textFieldAddress.frame.size.height-10);
float bottomPointPH = (textFieldPhoneNumber.frame.origin.y+ textFieldPhoneNumber.frame.size.height+10);
scrollAmountA = keyboardSize.height - (self.view.frame.size.height- bottomPointA);
scrollAmountPH = keyboardSize.height - (self.view.frame.size.height- bottomPointPH);
if (scrollAmountA >0 || scrollAmountPH >0){
moveViewUp =YES;
[self scrollTheView:YES];
}
else
moveViewUp =NO;
}
it gives me a problem with the userInfo part. I'm new to the iPhone SDK so if I'm doing something blatantly wrong, please be patient :)
dejo
Aug 3, 2009, 09:57 PM
I am still having a problem with the view moving up a second time when you jump from one text view directly to another.
In other words, your scrollTheView: is getting called even when you don't need it to, is that correct? You're gonna need to adjust the conditional of that if-statement then.
trojanvillage
Aug 3, 2009, 10:51 PM
Is there a way to set the First Responder while editing a textField to another textField when you click between textFields?
dejo
Aug 4, 2009, 09:12 AM
Is there a way to set the First Responder while editing a textField to another textField when you click between textFields?
There is. I would search the iPhone OS developer documentation for anything containing "firstresponder" and see what comes up.
trojanvillage
Aug 5, 2009, 12:21 PM
I'm looking for a way to reposition the view when you move between one textfield to another. Anyone know of a way to do this? I have read through the documentation and I'm having trouble understanding it. Apple suggests using notifications to tell you when the view should be moved but they want you to use a UIScrollView. I would like to use a standard View.
If you have any suggestions, please post below, with an outline. :)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.