1

Sorry for asking such a stupid question here.

Actually i have a list of textfield in which i am moving to next textfield by clicking on next button. Its working fine but in that textfields one is for date field and for that i am using date picker as input accessor.

When i am clicking directly on that textfield its working fine and date picker comes. But when i am coming to that textfield with next button keyboard is hiding my textfield.

For date picker display i am using textFieldDidBegin method. I have tried by using [textfield resignFirstResponder]; and [datePicker becomeFirstResponder]; But nothing is working for me .

Any help will be appreciated.

Thanks.

Sawant
  • 395
  • 6
  • 21

5 Answers5

1

You should use textField.inputView property for displaying date picker. Only in this case [textfield resignFirstResponder]; will work properly.

- (void)viewDidLoad {
  ...
  // Assume that self.datePicker contains configured date picker view
  // With added target on UIControlEventValueChanged action
  textField.inputView = self.datePicker;
  ...
}

P.S. You should send becomeFirstResponder only text field views, but not date picker. Date picker is just input view.

Paras Joshi
  • 19,954
  • 11
  • 54
  • 69
Ossir
  • 3,035
  • 31
  • 50
1

I also face same problem few days ago, i write following code for this scenario, First i disable userinteraction on dataTextfield but i have touch on complete UITableCell. And i override simple UITouch event method instead of textbegin delegate method. See my following code.

In tableviewController.h file

 #import <UIKit/UIKit.h>
 #import "CustomTableCell.h"
@class CustomTableCell;
@interface PersonalInfoTableViewController : UITableViewController<CustomTableCellDelegate>{
@property(nonatomic, strong) UITextField *previousTextField;
@end

In tableviewController.m file 

 @implementation TableViewController
 @synthesize previousTextField;
//When you create custom table cell set your CustomcellDelegate = self in tableView:cellForRowAtIndexPath method\
 //also assign previousTextField to CustomTableCell textfield

-(void)tableViewTouch{
[previousTextField resignFirstResponder];
}

 in CustomTableCell.h file
#import <UIKit/UIKit.h>
 @protocol CustomTableCellDelegate
 @optional
   -(void)tableViewTouch;
 @end
@interface CustomTableCell : UITableViewCell<UITextFieldDelegate>

@property(nonatomic, unsafe_unretained) id<CustomTableCellDelegate> delegate;
@property(nonatomic, weak) IBOutlet UITextFiled *theCellTextField;
@end

in CustomTableCell.m file
@synthesize theCellTextField, delegate;
  -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
 //Here my other method to show datepicker in popupViewController on tablecell.
  [delegate tableViewTouch];
  }

This is code for only ARC

Paras Joshi
  • 19,954
  • 11
  • 54
  • 69
Tirth
  • 7,665
  • 9
  • 52
  • 86
0

Give tag value to your textField and then

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag==6) {

        [textField resignFirstResponder];

        //Show your picker
    }
}
Rajneesh071
  • 29,619
  • 13
  • 57
  • 72
0

Give tag of each UITextField for datePicker container textfield with tag 102

-(void)textFieldDidBeginEditing:(UITextField *)sender
{

    if ([sender tag]==102)
    {
        [self.textFieldDatePiker resignFirstResponder];
        [self.alaramTime resignFirstResponder];
         .
         .
         . 
         //Write all textField with resignFirstResponder

        [self showPickerView];
    }

}
iPatel
  • 41,165
  • 13
  • 109
  • 131
-1

UITextField's textFieldDidBegin method gets called when textField became first responder.

So use textFieldShouldBeginEditing to not allow textfield editing. Also set tag for textfield where u need date picker.

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
 {
     if([textfield tag] == some tag no)
        [self.view endEditing:YES]; // in case if any textfiled is first responder before  date picker to open
        [datePicker becomeFirstResponder]; //open date picker
        return NO; // not edit textfield
     else 
        return YES; // edit textfield here for other case
 }
Paresh Navadiya
  • 37,381
  • 10
  • 77
  • 128