Help with my keyboard moving down!

Discussion in 'iOS Programming' started by trojanvillage, Aug 1, 2009.

  1. trojanvillage macrumors member

    Joined:
    Jan 1, 2008
    Location:
    Toronto
    #1
    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
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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:?
     
  3. trojanvillage thread starter macrumors member

    Joined:
    Jan 1, 2008
    Location:
    Toronto
    #3
    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;
    }
    
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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.
     
  5. trojanvillage thread starter macrumors member

    Joined:
    Jan 1, 2008
    Location:
    Toronto
    #5
    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 :)
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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.
     
  7. trojanvillage thread starter macrumors member

    Joined:
    Jan 1, 2008
    Location:
    Toronto
    #7
    Is there a way to set the First Responder while editing a textField to another textField when you click between textFields?
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    There is. I would search the iPhone OS developer documentation for anything containing "firstresponder" and see what comes up.
     
  9. trojanvillage thread starter macrumors member

    Joined:
    Jan 1, 2008
    Location:
    Toronto
    #9
    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. :)
     

Share This Page