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
  • 22
  • Show the code of your UITextField declaration? – Rushi Mar 07 '13 at 10:07
  • post the code you have written for resigning the keyboard – Niru Mukund Shah Mar 07 '13 at 10:10
  • http://stackoverflow.com/questions/1247113/iphone-keyboard-covers-text-field http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present Check this if you are asking keypad hides your textfield. – Cintu Mar 07 '13 at 10:18

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
  • 20,427
  • 11
  • 57
  • 70
Ossir
  • 3,109
  • 1
  • 34
  • 52
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
  • 20,427
  • 11
  • 57
  • 70
Tirth
  • 7,801
  • 9
  • 55
  • 88
0

Give tag value to your textField and then

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

        [textField resignFirstResponder];

        //Show your picker
    }
}
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
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
  • 46,010
  • 16
  • 115
  • 137
-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
  • 38,095
  • 11
  • 81
  • 132