Search code examples
ios4ios-simulatorkeypad

How to get rid of the keypad in the iphone simulator?


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 :)


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];
    }