Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

trojanvillage

macrumors member
Original poster
Jan 1, 2008
49
0
Toronto
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
 
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:?
 
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?
Code:
- (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;
}
 
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:
Code:
- (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.
 
problem 2

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:
Code:
- (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 :)
 
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.
 
Is there a way to set the First Responder while editing a textField to another textField when you click between textFields?
 
reposition the view

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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.