Objective C , Keyboard issue - objective-c

I am using XCode 4.2 .
is there a way to push the UITextField up when the user is entring text ?
the problem is that the UITextField is located behind the keyboard when it appears ...
Thanks

The one way is to simply manually shift the uitextfield up. You can simply use the delegate methods for uitextfielddelegate on begin editing and end editing to do your transformation.
Follow this.

Here is a simple tutorial on how to animate the textfield up when the keyboard comes up. The idea is to implement the UITextFieldDelegate methods like this
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// ANIMATE TEXTFIELD UP
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// ANIMATE TEXTFIELD DOWN
}
The tutorial has all the details along with working code.

Related

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.

How to catch a change in UITextField text?

I have looked at all the similar questions and they are different than from what I am asking. I need to catch a change in the actual text in the UITextField, not just the state of editing. It will be a first responder when the view loads, and I need to know when text is entered so that I can enable "Next" in the navigation bar. Please help me if you can it's really holding me back in my project.
Addition: I am currently using - it doesn't work:
[textField addTarget:self action:#selector(textFieldDidChange) forControlEvents:UIControlEventValueChanged];
Implement UITextFieldDelegate protocol, and respond to the textField:shouldChangeCharactersInRange:replacementString: method.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacementStr {
// Enable "Next" if you like what's entered in the replacementStr
}
Check the developer documents for UITextFieldDelegate, specifically this method

Make "Done" button work on TextField Keyboard

When adding a textfield, the keyboard opens correctly, however I cannot get the done button to work properly. I know thee are other similar posts, however for whatever reason they do not seem to work for me.
When I say "not work" i mean the keyboard does not close.
Any suggestions would be appreciated.
Add this and let me know:
- (BOOL)textFieldShouldReturn:(UITextField*)aTextField
{
[aTextField resignFirstResponder];
return YES;
}
Remember to add the viewController as delegate of your text field
I believe this is what you're looking for. Its a UITextFieldDelegate callback thats called anytime the Done/Return button is used on the keyboard.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
You'll need the delegate in your interface
#interface Class : UIViewController <UITextFieldDelegate>
If you're textfield is in a ModalViewController using the FormSheet style you need this as well.
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}

xcode 4.3 - UITextField - Custom Keyboard

I have two TextFields and I am designing a custom keyboard for ipad.
How can I dissmis system keyboard and let mine apear.
how can I know that the user is activating which TextField?
Setting the delegate to textfields to your view controller instance you have to implement this method:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
and if you return YES it will open the system keyboard, if you return NO it won't.
Before returning NO, of course, you can show your view.
You will know which textField is "pressed" using tag property.

tableview with text fields in each row having resignkeypad issue

i am adding the textfield on each row inside the cellforrow method of tableview,but when i type anything on any textfield ind try to resign textfield on view touch, but it only works for last row's textfield only. what is the solution for that issue,
please help.
Thanks
Dhananjay
if i understand you correctly this will probably work:
add the protocol to your viewController in question and add
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
// custom code
}
afterwards make sure that each textField has your viewController as delegate.