how to popup default iphone keyboard on a button click - iphone

Hi
When we click on a UITextField or UITextView, a default keyboard pops up from the bottom of iphone screen. I want iphone keyboard to appear on a button click, and then handle the keys as typed on keyboard... How can i do that?

Add touchupinside event on button and call becomeFirstResponder method for textview or textfield it will call pop up keyboard.
see the following code-
-(IBAction)buttonClicktoModalView:(id)sender{
[textView becomeFirstResponder];
}

I was searching my problem, and came across the following stackoverflow link which answers my question
How to pull up a UIKeyboard without a UITextField or UITextView?
Thank you

Pls go through this
iphone keyboard without textview
Hope this helps

Related

UIMenuController not showing UIPasteBoard is cleared iPhone app?

Am working in message based iPhone application. In my application looking like iMessage native iOS app. I made Bubbles with used UIImageView and UILabel. I made UILabel as clickable and showing Copy option. It is working fine when the message input UITextView is not in active.
1. I can show the "Copy" option when we clicking UILabel and the UITextView is not becomeFirstResponder.
2. When the user clicking the MessageTextView (UITextView) from the bottom of the screen the UITextView becoming first responder and keyboard is showing now. In this scenario if the user clicking the messabe bubble (UILabel) the UIMenuItem showing "Paste" on the bubble instead of "Copy".
3. If i click "Paste" from the bubble UIMenuItem already copied text will be pasting in UITextView. So the control fully in UITextView UIMenuController not activated in UILabel. So i cleared the text from UIPateBoard when the user clicking the Bubble (UILabel).
4. Now the UIMenuController not showing up even [self becomeFirstResponder]; not becoming in UILabel class.
The reason is when the UITextView is in becomeFirstResponder the control fully in that. not coming to UILabel. Could you please help me on this.
How to show UIMenuItem "Copy" when the user clicking UILabel if the keyboard is in visible the control is in UITextView? Could you please help me on this. I spent two days in this issue. Thanks in advance.
May be I am wrong.CONSIDER THIS ANSWER AS A COMMENT.
I tried to achieve like what you are trying to do. Thats not working too. I figured out I cannot make access the two views at the same time. Especially when I have any view becomeFirstResponder and you cannot access menu items of other view.
But if you try like this,you may succeed in your code.
1) In the touchesBegan: method, find the user touching inside your UILabel.
2) If that happens, then show a custom view with buttons like copy,paste and select like that.

Want to hide keyboard with the press of a button in iOS

I've got an app with user input to enter some numbers and instead of having to push the done key on the keyboard to hide it I'd like for the keyboard to go away when they press the calculate button but I have not been able to figure out how to do this. Some hints please?
Thanks
In iOS you need to "resign" from being first responder in order for the keyboard to be removed from the screen. Simply call resignFirstResponder on your textfield:
[_yourTextFieldWithNumbers resignFirstResponder];
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/resignFirstResponder

iPhone UITextView Did End On Exit properties?

Why is it that there is no Did End On Exit property for a UITextView? How do you resignFirstResponder to lower the keyboard when the user clicks the 'Done' button? A UITextField usually works by just linking 'Did End On Exit' from UIBuilder but UITextView doesn't have that option.
Most apps solve this problem by adding a button somewhere in your UI. For instance in Safari, when you pop up the Keyboard on a UITextView, it brings a Toolbar with it with Previous, Next, autofill and a Done Button, and the Done button implements [myTextView resignFirstResponder];
There is textViewDidEndEditing: in the UITextViewDelegate protocol that will do what you need I believe.

How to retract the Keyboard on touching the UITextView when keyboard is already up?

I am writing an application that has a UITextView which allows editing. When a user first touches UITextView, a keyboard shows up and I want to retract that keyboard when user again touches the UITextView e.g. I have entered some data in a textview and with keyboard still showing on the screen I tap on the UITextView which should cause the keyboard to retract.
Is there any way to achive this?
(I'm aware of providing a done button and doing this but I want to achive this by tapping on UITextView itself)
As an aside, I would urge you not to use toggle state elements on the iPhone. It's to easy to double tap in real world use. That is why the Apple apps all use the either the "return" key on the keyboard or the done button.
In the interface you contemplate, the users will find themselves closing and then accidentally reopening the keyboard about 10% of the time or more. It will make your app feel cumbersome and flaky.
You should call resignFirstResponder for the UITextView. Let's say you have an IBOutlet for the text view:
#property (nonatomic, retain) IBOutlet UITextView *comment;
Then [comment resignFirstResponder]; can be called from a touchesBegan or the like.
See e.g. How to Dismiss the Keyboard when using a UITextView.
What you are looking for is a large transparent uibutton "overlapButton" which always stays on top of the uitextview.
When the textview appears, you set the button hidden so you can tap on the textview freely.
[overlapButton setHidden:YES];
When tapping the textview, the keyboard will come up and the following method inside your textview delegate will get called:
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
[overlapButton setHidden:NO];
}
Here, you need to set visible the "overlapButton" so that while the keyboard is up, you can touch the button which now overlaps the textview. On the button action, you can hide the keyboard:
-(IBAction) overlapButtonTapped{
[myTextView resignFirstResponder];
}
After resigning the first responder, the following method will get called:
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
[overlapButton setHidden:YES];
}
After setting the hidden property accordingly for the button (like above), you have a "clear" textview again which you can tap again to show the keyboard.. etc .. etc ..
Cheers.
I agree with you TechZen. I've seen this happen! I would not advise this also! It also makes editing very hard if not impossible for edit/copy/paste gestures. On the other hand, if the man still wants this badly.. :P the code provided by me in my other post works a treat! Cheers.

How do you launch a UITextView (iPhone) in edit mode?

I'm working on an iPhone app with only one view, a UITextView, and I want it to launch all ready for typing (with the keyboard activated) but by default it requires the user to first tap the view before the keyboard appears. I've seen this done in other applications but haven't been able to figure it out. Thanks.
you need to use the -becomeFirstResponder method on your field:
[myTextField becomeFirstResponder];
This will pop the keyboard up. To hide the keyboard, use -resignFirstResponder.