Textfield voiceover issue - iphone

I am trying to present custom keyboard on UITextField.
Every thing works fine but when voice over is on and focus goes on UITextField, it says "uitextfield, double tap to edit". Once keyboard is on and again u tap it, it still says same message instead of saying "uitextfield is editing".
This problem persist only when we try to present custom keyboard view.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
field1.inputView=keyBoard;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return TRUE;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
As you can see there is not much in the code.Only line which create problem is
field1.inputView=keyBoard;
If you use Default keyboard then voice-over works as usual.

Related

how can I dismiss keyboard on Enter keypress

I want to dismiss my keyboard as I press RETURN key.
I have tried by putting button in view's back side.
But how can I do this by pressing RETURN key?
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
Don't forget to add the delegate UITextFieldDelegate
I'm presuming you're talking about a UITextField rather than a UITextView as your question isn't that clear? If so then ensure your class is marked as a UITextFieldDelegate in the interface file,
#interface MyController: UIViewController <UITextFieldDelegate> {
UITextField *activeTextField;
// ...remainder of code not show ...
}
and then you should implement the two delegate methods as below,
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
activeTextField = textField;!
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
activeTextField = nil;
[textField resignFirstResponder];
return YES;
}
However if you're using a UITextView then things are a bit more complicated. The UITextViewDelegate protocol lacks the equivalent to the textFieldShouldReturn: method, presumably since we shouldn’t expect the Return key to be a signal that the user wishes to stop editing the text in a multi-line text entry dialog (after all, the user may want to insert line breaks by pressing Return).
However, there are several ways around the inability of the UITextView to resign as first responder using the keyboard. The usual method is to place a Done button in the navigation bar when the UITextView presents the pop-up keyboard. When tapped, this button asks the text view to resign as first responder, which will then dismiss the keyboard.
However, depending on how you’ve planned out your interface, you might want the UITextView to resign when the user taps outside the UITextView itself. To do this, you’d subclass UIView to accept touches, and then instruct the text view to resign when the user taps outside the view itself.
Create a new class,
#import <UIKit/UIKit.h>
#interface CustomView : UIView {
IBOutlet UITextView *textView;
}
#end
Then, in the implementation, implement the touchesEnded:withEvent: method and ask the UITextView to resign as first responder.
#import "CustomView.h"
#implementation CustomView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void) awakeFromNib {
self.multipleTouchEnabled = YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"touches began count %d, %#", [touches count], touches);
[textView resignFirstResponder];
[self.nextResponder touchesEnded:touches withEvent:event];
}
#end
Once you’ve added the class, you need to save all your changes, then go into Interface Builder and click on your view. Open the Identity inspector in the Utility pabel and change the type of the view in your nib file to be your CustomView rather than the default UIView class. Then in the Connections Inspector, drag the textView outlet to the UITextView. After doing so, and once you rebuild your application, touches outside the active UI elements will now dismiss the keyboard. Note however that if the UIView you are subclassing is “behind” other UI elements, these elements will intercept the touches before they reach the UIView layer. So while this solution is elegant, it can be used in only some situations. In many cases, you’ll have to resort to the brute force method of adding a Done button to the navigation bar to dismiss the keyboard.
I hope you have done UIViewController <UITextFieldDelegate> and yourTextField.delegate=self;
and then in the delegate method
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
{
[textField resignFirstResponder];
return YES;
}
Make sure your view controller class is a delegate for your UITextField and then use the delegate method in that class:
#pragma mark - Delegate Methods
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
// Dismiss the keyboard when the Return key is pressed.
[textField resignFirstResponder];
return YES;
}

UITextField - resignFirstResponder Query

I have an application which has a couple of UITextField present to allow my user to enter their age, and another numerical value. Ideally, I want the keyboard to bring up the numeric keypad when the TextField is being edited. At present I have it set to Numer and Punctuation merely to make use of the 'Done' button to dismiss the keyboard as the Numeric pad does not have a done button.
In an attempt to use the Numeric keypad, I have tried to set it to dismiss by tapping the background of my main view.
-(IBAction)backgroundTapped:(id)sender;
I created the above action in my header file.
-(IBAction)backgroundTapped:(id)sender {
[ageEntry resignFirstResponder];
}
I have expanded on the above method in my implementation file to tell the ageEntry TextField to resignFirstResponder. I have also changed my main view to a UIControl class and connected the buttonTapped action to the relevant alert through Interface Builder. Yet when I touch the background nothing happens.
Any ideas?
Just detect the touch in your viewController's view using the method
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[urAgeField resignFirstResponder];
[urOtherField resignFirstResponder];
}
and resign the keyboard in this method
A much easier method is to add a inputAccessoryView to your text field. This input accessory view can be a UIToolbar with a single UITabBarButton for your Done button.
Much less of a hack, and will look like the accessory view that is used in for example Safari to dismiss the keyboard.
i had a similar problem. here is the solution..
EDITED
add
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(tap:)];
tap.numberOfTapsRequired = 1;
[self addGestureRecognizer:tap];
}
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
[ageEntry resignFirstResponder];
}

UITextField always resignFirstResponder

I am using a UIPickerView and I want my keyboard to never show up for some of my UITextFields. When I call resignFirstResponder on the UITextField after it is touched it doesn't make the keyboard go down.
- (IBAction) txtFieldClicked:(id)sender {
[txtField resignFirstResponder];
}
For each text field where you don't want to be able to show the keyboard, do:
[textField setUserInteractionEnabled:NO];
You can also check a corresponding block in the Interface Builder UI. This prevents the text field from receiving the touch event that would otherwise trigger it to display the keyboard.
Set text field delegate and implement its delegate methods
See UItextFieldDelegate
If you dont want the keyboard to pop up, return NO for all those text fields here
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if([textField isEqualTo:self.myTextField]) {
return NO;
}
return YES;
}

Resign keyboard when leaving textfield

Hey, I have created a textfield within two custom cells. One textfield shows the standard keyboard and the other the shows a pickerview when entered. The problem I have is when I move from the keyboard to pickerview textfield without clicking the "return" button on the keyboard, the keyboard doesn't resign. However when I do it using the "return" the keyboard resigns. Am using:
- (void)textFieldDidEndEditing:(UITextField *)myTextField{
[myTextField resignFirstResponder];
}
and can't work out why this isn't working.
Thanks,
William
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == pickertextfield)
{
[textfield1 resignFirstResponder];
[pickertextfield resignFirstResponder];
}
return YES;
}
Does your view controller adopt <UITextFieldDelegate>? Is it hooked up as the delegate of your text fields?
Try using [self.view endEditing:YES]; before showing the pickerview and see it it helps.

iPhone keyboard, Done button and resignFirstResponder

This is probably a dumb question, but I can't find the answer in the docs. Did the "Done" button on the pop-up keyboard always cause the keyboard to disappear? I see a lot of code around the web like this:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[theTextField resignFirstResponder];
return YES;
}
When I press the "Done" button, the keyboard pops down and the UITextField resigns first responder.
I'm presuming that pressing the "Done" button didn't used to cause a UITextField to resignFirstResponder, but that behavior changed at some time.
I'm debugging on OS 3.0 - 3.1.3
I made a small test project with just a UITextField and this code
#import <UIKit/UIKit.h>
#interface TextFieldTestViewController : UIViewController
<UITextFieldDelegate>
{
UITextField *textField;
}
#property (nonatomic, retain) IBOutlet UITextField *textField;
#end
#import "TextFieldTestViewController.h"
#implementation TextFieldTestViewController
#synthesize textField;
- (void)viewDidLoad
{
[self.textField setDelegate:self];
[self.textField setReturnKeyType:UIReturnKeyDone];
[self.textField addTarget:self
action:#selector(textFieldFinished:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[super viewDidLoad];
}
- (IBAction)textFieldFinished:(id)sender
{
// [sender resignFirstResponder];
}
- (void)dealloc {
[super dealloc];
}
#end
The text field is an unmodified UITextField dragged onto the NIB, with the outlet connected.
After loading the app, clicking in the text field brings up the keyboard. Pressing the "Done" button makes the text field lose focus and animates out the keyboard. Note that the advice around the web is to always use [sender resignFirstResponder] but this works without it.
In Xcode 5.1
Enable Done Button
In Attributes Inspector for the UITextField in Storyboard find the field "Return Key" and select "Done"
Hide Keyboard when Done is pressed
In Storyboard make your ViewController the delegate for the UITextField
Add this method to your ViewController
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
From the documentation (any version):
It is your application’s
responsibility to dismiss the keyboard
at the time of your choosing. You
might dismiss the keyboard in response
to a specific user action, such as the
user tapping a particular button in
your user interface. You might also
configure your text field delegate to
dismiss the keyboard when the user
presses the “return” key on the
keyboard itself. To dismiss the
keyboard, send the
resignFirstResponder message to the
text field that is currently the first
responder. Doing so causes the text
field object to end the current
editing session (with the delegate
object’s consent) and hide the
keyboard.
So, you have to send resignFirstResponder somehow. But there is a possibility that textfield loses focus another way during processing of textFieldShouldReturn: message. This also will cause keyboard to disappear.
One line code for Done button:-
[yourTextField setReturnKeyType:UIReturnKeyDone];
And add action method on valueChanged of TextField and add this line-
[yourTextField resignFirstResponder];
I used this method to change choosing Text Field
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ([textField isEqual:self.emailRegisterTextField]) {
[self.usernameRegisterTextField becomeFirstResponder];
} else if ([textField isEqual:self.usernameRegisterTextField]) {
[self.passwordRegisterTextField becomeFirstResponder];
} else {
[textField resignFirstResponder];
// To click button for registration when you clicking button "Done" on the keyboard
[self createMyAccount:self.registrationButton];
}
return YES;
}