Question

I am making a simple iphone application where I have certain textfields one below the other. the problem is when I am adding data into these first few fields via my keyboard in the simulator, the keypad also pops-up which I am not using for typing as I am still using the simulator not the actual phone. Now I can't type data into textfields hidden by the keypad.

Sorry If my question is silly, there could be a shortcut for that, But I am new and StackOverflow is my only back option when I can't find things on Google search :)

Was it helpful?

Solution

Use your simulator keypad for entering the user inputs and write code for moving up the textfields so that keypad doesn't hides the text fields. Connect the delegate to text fields.

I am using this for moving up and down: in view did load,

{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
 }

and the following methods

- (void) keyboardWillShow: (NSNotification*) aNotification
{    
    int position = 0;


    if ([txtfld1 isFirstResponder])
        position = 120;
    else if ([txtfld2 isFirstResponder]) position = 120;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    CGRect rect = [[self view] frame];
    rect.origin.y -= position; 
    [[self view] setFrame: rect];
    [UIView commitAnimations];

}
- (void) keyboardWillHide: (NSNotification*) aNotification

{
    int position = 0;


    if ([txtfld1 isFirstResponder])
        position = 120;
    else if ([txtfld2 isFirstResponder]) position = 120;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    CGRect rect = [[self view] frame];
    rect.origin.y += position; 
    [[self view] setFrame: rect];
    [UIView commitAnimations];
}

OTHER TIPS

Simply Add textField Delegate.. AND This IS Its Delegate Method

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
      ["your Textfiled object Name" resignFirstResponder];
    }

Set Your all textFiled Like above. Your Keyboard will Be Dismissed. And I suggest To keep Your Textfields In Scrollview. It helps You

You're probably searching for something like the "Back Button" in Android, which dismisses the keyboard on the Android Emulator in any case. In the iOS Simulator you don't have a shortcut or button which works like that. You will be able to dismiss the keyboard with the return button, but only if you have hooked up an UITextFieldDelegate in your code first. Use this code to make your return button "work".

Alternativly you could Add a RETURN key(DONE,GO...) from The Attributes Inspector.

I am using the following answer to solve the problem.I hope this is really helpful to you. You simply using this code in your view controller.m file

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self animateTextField:textField up:YES];
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self animateTextField:textField up:NO];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top