views:

84

answers:

3

hi !

so in my viewdidload i got something like

[nameTextField becomeFirstResponder]

now after a button gets klicked, i want to slide out the keyboard of this textfield, and slide another keyboard of another textfield in.

i thought about

[nameTextField resignFirstResponder];
[dateTextField becomeFirstResponder];

but the other keyboard shows up immediately.

commenting the [dateTextField becomeFirstResponder]; out, effects that my nameTextField keyboard slides out as i wanted.

any ideas how to do this?

thanks!

+1  A: 

Is there a reason why you want to do this? It will obviously increase the time it takes for a user to enter information, which I know would bug me.

But if you do really want this effect, then I would look at something like this:

[dateTextField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:timeDelay];

Where timeDelay is the amount of time it takes to dismiss the first keyboard.

Tom Irving
thanks , worked perfectly. `0.5` is the perfect timedelay. still not shure if i will enable this "feature", 1 second could be a long time. thanks anyway!
choise
+2  A: 

You can register to observe these notifications: UIKeyboardWillShowNotification , UIKeyboardWillHideNotification. That will let you keep track of what is going on, but it can easily get pretty complicated so Tom Irving's suggestion might be easier to work with.

Felixyz
A: 

To get notifications on keyboard hiding and showing, have a look at

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:)
    name:UIKeyboardDidHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) 
    name:UIKeyboardDidShowNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
    name:UIKeyboardWillHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification object:[self view].window];

and add appropriate methods like

-(void)keyboardWillShow:(NSNotification*)notif
-(void)keyboardWillHide:(NSNotification*)notif
-(void)keyboardDidShow:(NSNotification*)notif
-(void)keyboardDidHide:(NSNotification*)notif

Then you can connect the animations any way you like.

Be sure to NSLog() all of them, they are not always called when you would expect them (the notorious one being when you go from one field to another, and you receive the willhide and willshow immediately)

mvds