How to call numpad using action button not from text field - iphone

I know this is silly question but as a beginner at xcode, and i can't find the answer from any source, can i call numpad (numberic keyboard) from my action button? I just want my action button can call numpad like text field do. what code should i insert in my action button?
my code:
- (IBAction)setLoopBtn:(id)sender
{
}
Thank you again for sharing your knowledge to noob like me.

Create a UITextField with a frame that puts it off the visible screen. Assign the type of keyboard you want to display as the default for that field. When the button is tapped, send becomeFirstResponder to your off-screen field.

-(IBAction) ButtonClick
{
txtField.keyboardType = UIKeyboardTypeNumberPad;
[txtField becomeFirstResponder];
}

Related

How to add a custom clear button in UITextField?

I want to resize the default clear button of UITextField. After I googled a lot, I came to know there is no way to modify it.
So I decided to go with Custom option ie, by adding UIButton to text field.I found some code from S.O, but nothing works for me. These are the links which I referred.
Custom UITextField clear button
Custom clear button for UITextField
Custom clear button in UISearchBar text field
So please suggest some solution which behaves exactly as default clear button of UITextField
Any help will be appreciated.
Thanks in advance.
In addition to the jake9115 response, you can emulate the clearbutton behavior by using the UITextFieldDelegate callbacks.
You can try in this way:
Show the button when -textFieldDidBeginEditing: is called
Hide the button when -textFieldDidEndEditing: is called
Hide the button if in -(BOOL)textFieldShouldClear:(UITextField*)textField the length of the textField's text is 0.
Why not just make a button that sets the TextView's value to ""?
- (IBAction)button:(id)sender {
_myTextView.text = "";
}

Working With Stacked UIButtons

Hey guys, so I have this search bar in my view along with many buttons below it. So when the search bar is tapped, a keyboard pops up, however I want the user to be able to click anywhere below the search bar and above the keyboard to get out of searching mode. I have been scavenging SO for a bit and came across a solution that suggested that I create an invisible button which intercepts touch events which I can use to resign first responder status from the search bar. And I can merely hide/disable the button when I do not need it so that the buttons below it may be tapped right? Wrong. setHidden nor setEnabled: aren't doing the trick. Here is the relevant code:
//touch event on button outsideSearchBarButton which is invisible
- (IBAction)selectOutsideSearchBar:(id)sender {
NSLog(#"Selected outside search bar");
[searchBar resignFirstResponder];
[outsideSearchBarButton setEnabled:NO];
[outsideSearchBarButton setHidden:YES];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)aSearchBar {
NSLog(#"searchbarTextDidBeginEditing");
[outsideSearchBarButton setHidden:NO];
[outsideSearchBarButton setEnabled:YES];
}
Setting the button to disabled or hidden via nib file does not help me at all. Either the button never exists (I can't click between search bar and keyboard and have keyboard go away) or always exists (I can't click any of the buttons below this invisible button). Any help appreciated. Thanks in advance!
//touch event on button outsideSearchBarButton which is invisible
- (IBAction)selectOutsideSearchBar:(id)sender {
NSLog(#"Selected outside search bar");
[searchBar resignFirstResponder];
outsideSearchBarButton.userInteractionEnabled = NO;
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)aSearchBar {
NSLog(#"searchbarTextDidBeginEditing");
outsideSearchBarButton.userInteractionEnabled = YES;
}
Do this.
go to the interface builder and select the button on which you are removing the keyboard during search, then select layout from the above menu and select send to back.Then in the inspector window set the button style to custom.
Hope this helps you.......

how to popup default iphone keyboard on a button click

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

iPhone: is there another way of yielding First Responder status?

Problem: If you have a big form with a lot of text input fields with number pad, you would not want to tell every single text field something like
[myTextField1 resignFirstResponder];
[myTextField2 resignFirstResponder];
instead, it would be great to just tell for example an invisible background button, that it is the First Responder as soon as the user tabs outside of any text field.
Like in JavaScript, when you give an element the focus(), all others lose it. How can I do that in UIKit?
[button becomeFirstResponder];
In your header file, paste this: -(IBAction)backgroundClicked:(id)sender;
in your implementation file, paste this:
(IBAction) backgroundClicked:(id)sender
{
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
In InterfaceBuilder, create a button that covers the entire view.
with the button selected, click Layout > Send to Back
Control drag from the button to File's Owner and select the outlet called: backgroundClicked.

How to disable input pad when pressing done on iphone?

I want to disable input pad on iphone when pressing 'done'. Any ideas about how to detect button press event?
Programatic Method
To register button press events you can either do the programmatic approach:
[button addTarget:self action:#selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside]
Where buttonPressed: is a method in the class "self":
-(void)buttonPressed:(id)sender;
You can specify a pointer to any object instead of "self" of course, as long as the object has a buttonPressed: method.
Interface Builder
You can also use Interface Builder. Create a method that you want to execute:
-(IBAction)buttonPressed:(id)sender;
Then right click on the button in interface builder. You should see a list of actions. On the "touch up" action click on the circle button, and drag a connector to the object representing the class where you put the buttonPressed: method.
Disabling Input Pad
I'm not sure what you mean by this. Are you talking about dismissing a keyboard input? If so, you have to call the "resignFirstResponder:" method. Say, for example, the keyboard pops up because you are editing a text field. To dismiss the keyboard call the following method on the text field:
[textField resignFirstResponder];