iOS7:editable textfield cells in tableview is not working properly - objective-c

Editable textfield cells Tableview is causing problem on keyboard tab button everytime it is calling textfieldshouldbeginediting even if i am in first textfield it is not going to nextfield.
It is going to last textfield and if popover is availabe it will crash.How can i fix this so that if enter tab then it has to resign current responder in textfielddidendediting and it should not go to textfieldshouldbegin editing.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
PickerViewController *selectOperatorController;
NSLog(#"tag %d",textField.tag);
return NO;
}
I also declared textfield delegates like didendediting and shouldendediting
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
activeField = nil;
if (self.chooseOperatorController) {
[self.chooseOperatorController dismissPopoverAnimated:YES];
}
return YES;
}
This is not as issue in iOS 6.But it is in iOS 7.

textfieldshouldbegin editing will not allow desktop keyboard tab button input,it cannot judge to move between the textfields.If we add textfielddidbeginediting we can move the controls,eventhough we have two methods we can move by using keyboard tab.So textfielddidbeginediting is mandatory if we want to move bewtween available textfields.

Related

Editable textfield in popover not working

I'm working on an Mac App that uses popover windows for additional functionality. I have a popover that opens where I need the user to input some text and I can't seem to get the field to be editable. Under the Attributes inspector in Xcode the behavior is set to be editable and the other options match settings from a similar application that has a text field in a new window that is editable. What am I missing?
- (IBAction)dataTransferButton:(id)sender {
[[self dataTransferPopover] showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxXEdge];
_employeeCheckBox.enabled=NO;
[dataTransferPopover becomeFirstResponder];
userAccountTextField.editable=YES;
}
Make your app delegate implement NSPopoverDelegate and implement
-(void)popoverDidShow:(NSNotification *)notification
{
[self.dataTransferPopover.viewController.view.window makeKeyWindow];
self.dataTransferPopover.viewController.view.window makeFirstResponder:userAccountTextField];
}
You need to make the textfield as first responder not the popover.

Hide the keyboard for UITextField in the same UIViewController with UISearchbarDisplayController

How can I hide the keyboard only for specific UITextFields?
I have a lot of UITextField in a View Controller, which has also a SearchbarDisplayController.
I tried to use this but it blocks the UISearchbarDisplayController's job.
Thank you.
For more detail:
For example I have 3 UITextFields and a searchbar display controller. If there is only UITextFields , while tapping out ofthe keyboard, the keyboard successfully disappear. But when I touch the searchbar, you know the keyboard is open and I enter some text to searchbar. So it gives me some results in searchresultstable of the searchbar. But I can't select any row from searchresultstable. Because the disapper keyboard blocks it.
it seems to me that in this tutorial this method has not been implemented, try to add it
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}

UITextView won't resignFirstResponder so another can becomeFirstResponder

I have a toolbar in my UITextfields' inputAccessoryView. If the 'next' button is hit it makes the next textfield in an orderedSet of all my textfields become the first responder. THAT works perfectly.
BUT I can't get the 'previous' textfield to becomeFirstResponder.
I've checked in the console and the textfield does call textFieldShouldBeginEditing and I am returning YES but it never calls textFieldDidBeginEditing and the textfield that should resignFirstResponder never calls textFieldShouldEndEditing.
So the textfield is getting the message to becomeFirstResponder but doesn't.
- (IBAction)keyboardBarButtonDidTouch:(UIBarButtonItem *)sender
{
if (sender==self.previousBarButton&&self.activeTextFieldArrayIndex.intValue>0)
{
[(UITextField *)[self.textfields objectAtIndex:(self.activeTextFieldArrayIndex.intValue-1)] becomeFirstResponder];
}
if (sender==self.nextBarButton&&self.activeTextFieldArrayIndex.intValue<(self.textfields.count-1))
{
[(UITextField *)[self.textfields objectAtIndex:(self.activeTextFieldArrayIndex.intValue+1)] becomeFirstResponder];
}
if (sender==self.doneBarButton)
{
[self.activeTextField resignFirstResponder];
}
}
The weirdest thing is that if I force the textfield to resignFirstResponder by some action that just does that, the 'previous' textfield suddenly becomesFirstResponder. Like it was being added to a list of responders and it became its turn....
And as is often the case when strange things happen, it was unrelated to becoming first responder. I was accidentally changing my activeTextfield pointer to nil in the middle of a bunch of logic by way of the textfield delegate. ^o^
Disregard!
1) Try making your code less error prone.
instead of this
if(sender==self.previousBarButton&&self.activeTextFieldArrayIndex.intValue>0)
do this
if ((sender==self.previousBarButton) && (self.activeTextFieldArrayIndex.intValue>0))
2) use textfield.tag property and set unique tags for these text fields. and do your stuff about become/resign first reponders by using
(uitextfield *)field[self viewWithTag: uniqueTag];

How to dismiss keyboard when the UISearch Bar 'Search" button is pressed?

I've implemented a UISearch bar with the searching functionality set up, however when I press the "Search" button on the keyboard that shows up nothing happens. How can I get the keyboard to hide when the "Search" button is pressed while keeping the text in the search bar intact (To keep the search results present)?
From Text, Web and Editing Programming Guide for iOS:
To dismiss the keyboard, you call the resignFirstResponder method of the text-based view that is currently the first responder.
So you should do this in your UISearchBarDelegate:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
// Do the search...
}
Swift 4
Make sure you have UISearchBarDelegate defined in your UIViewController
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}

Bring to front DatePicker on an UITextField

When an UITextField is firstResponder, I would like to bring to front an UIDatePicker (bottom part of the screen) without the "going down keyboard" (no call to UITextField resignFirstResponder).
The aim is to process like UIKeyboard of UITextField which pop-up on nearly everything when it becomeFirstResponder. modalViewController seems to be fullscreen only.
- showDatePicker:(id)sender {
if([taskName isFirstResponder]) [taskName resignFirstResponder];
[self.view.window addSubview: self.pickerView];
// size up the picker view and compute the start/end frame origin
(...)
[UIView commitAnimations];
}
This example is an animation of keyboard going down, and DatePicker going up, behind and not in front.
Do you know a solution ? A piece of code would be welcome. Thanks in advance.
This is simply done by setting the input view of the text field to the Picker View. Then, on Editing did begin tell the picker view to becomeFirst responder. Like this
textField.inputView = pickerView
then using an IBAction called when the Editing Did Begin
-(IBAction) setPickerViewAsFirstResponder:(id)sender
{
[pickerView becomeFirstResponder];
}
This works perfectly. You'll need to implement code to actually set what the picker view is currently showing to be a string in the text field still.
This definitely can be done... simply implement the method below after setting UIViewController <UITextFieldDelegate> in your .h
Long story short, this overrides the keyboard loading before text editing begins.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Make a new view, or do what you want here
UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,245,0,0)];
[self.view addSubview:pv];
return NO;
}