TextField with Keyboard in cocos2d ! - iphone

I am trying to develop a iphone app by using cocos2d. I create a alert view with a text field. when I touch the text field then comes the keyboard. But I want that when the alert is open, in the same time textfield will be selected and keyboard comes(without any touch). how can it posible ? sorry for my bad English.

[myTextField becomeFirstResponder] will probably do what you want.

That would be a little tricky to do. The controls in iPhone use the concept of "first responders" Any events will be handled by the first responder in the controller. Now, when an alert view is displayed, it becomes the first responder so it can respond to button clicks. When a text field is selected by the user, the keyboard gets the control. So I guess what you want to achieve can be done by making the text field the first responder after showing the alert ([txtField becomeFirstResponder])
But I have no idea how the alert view's responses will be handled then. You won't be able to click the OK button on the alert view till the keyboard is dismissed and you resign the first responder of the text field. ([txtField resignFirstResponder]) (This is just a guess, you will have to check the final behavior)

[myTextField becomeFirstResponder] works -- I tested it.

Related

UITextField Hide Keyboard But Reamin First Responder?

I've subclassed a UITextField to display a UIDatePicker instead of a keyboard. Entering dates is something that happens often I our app. The problem occurs when another of our custom classes that accommodates the keyboard needs to know what the first responder.
Is there a way to remain first responder, whilst hiding keyboard?
No, you have to resign as responder (give up focus) to dismiss the keyboard.
Edit: It seems I lied. Try [self.view endEditing:YES];
FYI: It only works on iOS 3.2+
Actually, instead of subclassing, you should just make a custom inputView for your text field which uses a date picker as the custom "keyboard". Then, it will remain the first responder and never even call the system keyboard in the first place.

How do you keep the keyboard visible after you click the Send key

In my iPhone APP I have a view with a textfield and a button (to remove the view).
My main goal is to have the keyboard always visible.
I made a "Send" button visible on the keyboard and am able to capture when the send button is pressed.
Hoever, when you press the send button the keyboard is removed. What I would like is for the keyboard to remain visible and the text from the textfield to be cleared and be textfield to have focus ready for some more typing.
Adding:
[textChat becomeFirstResponder];
in the Did End On Exit event does not work. I am not sure if I should be using one of the other events.
There are a ton of samples and tutorials on how to remove the keyboard, not one on how to keep it.
The keyboard is removed when it stops being the first responder. There is a delegate method you can implement, textFieldShouldEndEditing:, which is called when the text field is asked to resign from being first responder. You could implement this and have it return NO after you do whatever you want to do with the data in the text field (send it somewhere), clear the field, etc.

iPhone- After resigning first responder on UITextField, can't refocus it

I have a modal window that's used for searching data from a remote server- it has a UITextField as the titleControl of the navbar for the window, and a tableview filling the window (that displays the results obviously). Now what I want to do is when the user scrolls the tableview, immediately have the textfield lose focus (resign first responder) so that the keyboard dismisses and the user has more room to scroll through the tableview (it stretches down to fill the gap left by the keyboard). Basically the same functionality as when using a UISearchDisplayController (or whatever it's called).
So I have this code for detecting the scroll event of the tableview:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[searchField resignFirstResponder];
}
Which works fine. However, the issue is that once the user scrolls the table and the textfield loses focus, you can't give focus back to it by tapping on it again. So basically once I call that [resignFirstResponser] I can never again bring the keyboard back up and edit the textfield value. Anyone have any idea why? Do I need to explicitly call [becomeFirstResponder] on the field somewhere? Because I thought that was handled automatically when the field is tapped?
Also of note- I am calling [becomeFirstResponder] on the text field right when the modal window is first called up, so the field is pre-focused. Could that have anything to do with it?
I can post more code if anyone would like, but I don't think I'm doing anything out of the ordinary with the textfield.
Thanks for any help!
You are calling the resignFirstResponder from a function which will be called everytime you scroll the UIScrollview. Hence it does not appear. You need to call resign when the uitextview goes out of focus.
You can do the following. Its a hack:
Whenever you focus on the UITextField create a invisible button to overlay your scroll view.
Capture the button press event and resign first responder
Whenever the uitextfield becomes first responder create the button
This way you will remove the bug, viz calling the method in scrollViewWillBeginDragging.
Other option would be to overrite viewDidAppear method for the uiTextField.
Or you could put your textfield into a different container and handle scrollViewWillBeginDragging by checking which scrollview sent the message.
Did u set a delegate for you searchField? I had the same issue. I popup a model view, and set the text field to be the first responder inside viewDidLoad. Everything works well for the first time. But once I dismiss the modal view controller, and reopen it. my text field cannot be focused anymore.
I found it has something to do with methods of UITextFieldDelegate. Once I remove implementation for methods
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
everything works well. but don't know why
Are you doing anything with "textFieldShouldEndEditing", like #fengd?
A problem that I had was that I was viewing a modal view, and my "textFieldShouldEndEditing" routine was incorrectly returning "NO" on a specific text field. When my modal got dismissed, I would be unable to tap on any other text-field, presumably because the old text field was still "first responder". Since it can never end editing, it fouls up all other text fields that come after it.
I realize this is 2 yrs after the fact, but maybe someone else might find this useful.

ipad keyboard resize problem

I have a "new message" view controller in my app (just like the system sms app) where there are two textfields, one for receivers and one for the message content. The problem is when I switch between the two textfields, the keyboard may resize (depending on the input method), and I don't get any keyboard notifications. This is rather embarrassing since the keyboard may cover the textfield, which is not what i want. How can I fix this?
thanks in advance.
You can set your controller as the delegate of your text fields and when textFieldShouldBeginEditing: or textFieldDidBeginEditing: is called, perform any necessary manipulations to your view to make sure the textField is visible.

How to keep UIKeyboard when textfield is regisned first responder?

I'm writing an app that has a view similar to the SMS app's text editing view. It has a textview on the top and a textfield on the bottom. I want to allow users to copy and paste texts in the textview while keeping the keyboard appear. But if I try to copy the text, the UITextField will resign first responder and the keyboard will missing. Any ideas about how can the SMS app keep the keyboard while user is copying texts in another view?
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return NO;
}
I've tried to return NO for -(BOOL)textFieldShouldEndEditing: , but the textview to the upper cannot copy text then.
Related Option:
Just Give a button on Topbar or anywhere else that have option to copy the text then its more user friendly..
Second Option:
If you have much good know programming concepts then just create the new view above the keyboard and animate when keyboard is show and don't resignfirstresponder, and following options are their, copy text, done, in the done action you have resign first responder
Those are only option which u have done if you want more userfriendly app because in appStore and appReview Department have verify the User Convenience UI Integrations and you must full fill that and from the other side user's whom purchase or download the app also give the awesome comments on the app who is more reliable and cashless functionalities ....
I've tried to return NO for -(BOOL)textFieldShouldEndEditing: , but the textview to the upper cannot copy text then.
add a textfield so it can scroll and set the dimentions or just add the scrollbar to scroll it to .. it will solve your problem