How to add Done Button to dismiss the Number Pad - objective-c

I followed the tutorial:
http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key
to dismiss the number pad,
this tutorial add the button as sub view to the number pad,
my problem is, in the same view I am using the text field to enter text also,so, how to differentiate the number field, and text field. so that I can hide the button view accordingly.

Yoy can use UITextFieldDelegate Protocol instead of NSNotifications, and inside methods textFieldDidBeginEditing: and textFieldDidEndEditing: check which field is being used. Something like this:
- (void) textFieldDidBeginEditing:(UITextField *)textField {
if (textField == self.passwordField) {
// add subview...
}

Related

Using a Date Picker with a UITextField and disabling other input

So i've got a dat picker setup as a UITextField's inputView, all is working well. The problem however is that when you select the text field (and the picker shows up), you're still able to type in letters (on a simulator using computer's keyboard). How can I set it up so that when you tap on the text field and the date picker shows up, you cannot enter any additional text?
You can code your UIViewController to implement the UITextFieldDelegate protocol, assign the delegate for textField and then write the following function in your view controller :-
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}

How to enable the next textfield in Objective C

I have two textfields (a username and a password) field and I remember that sometimes the keyboard has a little < or > to navigate through the textfields and I was wondering if there is an option or code that would allow me to do this natively in my app. Any tips or hints are appreciated. Thanks!
If you would like an acceptable solution that doesn't involve implementing a third party library, you can do it like the following:
Set the return button on the virtual keyboard to be a "Next" button for the username field, and a "Go" button for the password field, and make your view controller a UITextFieldDelegate. Set your view controller as the delegate for both text fields, then implement the textFieldShouldReturn: like the following:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.username) {
[self.password becomeFirstResponder];
}
else if (textField == self.password) {
[self.password resignFirstResponder];
[self signInPressed];
}
return YES;
}
This will make it so if you have the username field selected, the "Next" button on the keyboard will advance to the password field, and when the password field is selected, the "Go" button will call the signInPressed method, which you just change to whatever you have your sign in method named.
There's no builtin way to add these buttons.
Look into inputAccessoryView to understand how to extend the keyboard.

Enabling Done Button When User Changes Values - Xcode

I am trying to make it to where if any value is typed on the keyboard without hitting the return key and two of the labels have been changed from "Select" to something else, the button up at the top becomes enabled. However, I have tried using an IBAction saying:
- (IBAction)valuesChanged {
if (textField.text != nil && ![labelOne.text isEqualToString:#"Select"] && ![labelTwo.text isEqualToString:#"Select"]) {
NSLog(#"Success");
}
else {
NSLog(#"No Success");
}
}
But I have realized that this does not work because:
The textfield does not work when I put the IBAction Sent Event as "Value Changed"
The labels won't accept an action.
How do I go about doing this?
The text field delegate method that tells you that the user is typing a character in the text field or otherwise changing its contents is textField:shouldChangeCharactersInRange:replacementString:. Implement it in your text field delegate and respond as appropriate. You will also just return YES.
One reason your original code couldn't be hooked up might be that you have not used the canonical form of an IBAction method; it should be
- (IBAction)valuesChanged:(id)sender {
Another problem in your original code is that a UITextField does not emit Value Changed. What you wanted was Editing Changed. But the delegate method works just as well.
Try UITextField delegate methods.
- (void)textFieldDidBeginEditing:(UITextField *)textField;
- (void)textFieldDidEndEditing:(UITextField *)textField;

Xcode - setFocus on a text field, becomeFirstResponder isn't enough

At the moment, I trigger a method on 'Did End On Exit' in my app (I'm aware that this may not be the greatest way of doing it but I'm very new to Objective C and Xcode for that matter and I'm simply doing what feels comfortable to me).
This method resigns the firstResponder from the current text field and applies it to a later text field.
The problem I'm facing is that the keyboard covers the next text field so that the use has no idea where the focus is and therefore what they are required to type.
How do I get it so that my keyboard shifts down and actually shows the text box that is currently active? Making something the firstResponder simply doesn't do what I want it to, unless there's part of the implementation I'm missing.
Here's my simple method:
- (IBAction)firstNameNext:(id)sender {
[firstNameTextField resignFirstResponder];
[surnameTextField becomeFirstResponder];
}
Any advice would be super.
Add UIScrollView in your main view then all contents as subview to UIScrollView
Now when specific UITextField needs to be able to visible in view use its delegate like this:
Note: add UITextFieldDelegate in .h file like this
#interface yourViewController : UIViewController<UITextFieldDelegate>
Also bind with File's Owner
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
{
if(textField == yourSpecficTextField) //one u want move upwards
{
yourScrollView.contentOffset = CGPointMake(0,200); //required offset
}
... //provide contentOffSet those who needed
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
yourScrollView.contentOffset = CGPointMake(0,0); //make UIScrollView as it was before
}
If you have keyboard input fields that will be covered by the virtual keyboard, then you need to move those fields out from under the virtual keyboard.
The normal way to do this is to have the controller's view be a scrollable view like UIScrollView. Moving Content That Is Located Under the Keyboard gives a very robust way of adjusting your scroll view and ensuring the required field shows.

Text entry ios question

I have two UILabels in a view that display my band and song name as strings. I am working on also adding the option to change either of these strings manually. I want to keep it as is, and I've added 2 buttons to manually enter a song name or band name. The thing is, all the text editing as far as I understand it needs to have actual TextField or TextView to bring up the keyboard etc.
I just want to touch one button for "enter song name" and be given a keyboard and when enter is hit, replace the string in the uilabel with that string, and the same for enter band name uibutton, and change the uilabel again.
Problem is in the docs I don't really understand how to do this. Does anyone have an idea about text entry in ios and can give me a pointer/tip on how to do this?
Just Declare your label Global and implement in implementation method
Take all song and all album data in array
and display all data in table view
now by using Delegate method of
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
change the text of Label as u want
#interface songViewController ()
{
UILabel *bandLabel;
UILabel *songLabel;
NSArray *bandData;
NSArray *songData;
}
#end
#implementation songCreateViewController
- (void)viewDidLoad {
[super viewDidLoad];
{
bandLabel=[[UILabel alloc]init];
bandLabel.frame=CGRectMake(40, 580, 500, 30);
bandLabel.text=#"Join group as";
[self.view addSubview:bandLabel];
songLabel=[[UILabel alloc]init];
songLabel.frame=CGRectMake(40, 580, 500, 30);
songLabel.text=#"Join group as";
[self.view addSubview:songLabel];
}
#pragma mark Table view Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView==albumTableView)
{
bandLabel.text=[bandData objectAtIndex:indexPath.row];
}
else
if(tableView==songTableView)
{
songLabel.text=[songData objectAtIndex:indexPath.row];
}
#end
What you are going to have to do is replace the label with a text field and set that as the first responder when the user presses the button. You will need a class that is the delegate of the text field so you handle enter in the textFieldShouldReturn method to resign first responder on the text field (to close the keyboard) and change the text field back to the label view and update its contents.
It can be achieve by many ways..
1) you can use hidden in your button methods to hide label and show textView.
2) you can use textField in place of label, make textfield.editable=NO and when button is pressed just clear the textfield by textfield.text=nil and make textfield editable.
Try these..
You want like when user touch on button you want to add text and button should be look like UILable. is it your objective?
If I am right you can achieve this thing to add gesture in uilable, you don't need to add button and handle tab method you can change the text.
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
myView.addGestureRecognizer(tap)
#objc func handleTap(_ sender: UITapGestureRecognizer) {
print("Hello World")
}