Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnmerlino

macrumors member
Original poster
Oct 22, 2011
81
0
Hi all,

I implemented a tab bar controller. One of the tab items takes user to a page where they can filter date ranges. When user selects in text field, rather than keyboard poppping up, a datepicker pops up and has a toolbar with a button item on it. When user clicks on button, the toolbar and datepicker are hidden. Problem is now when I try to select another tab bar item, it is no longer responsive.

Here's my code:

Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
        
    self.datePicker = [[UIDatePicker alloc]init];
    [self.datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(addButtonPressed)];    
    
    [toolbar setItems:[NSArray arrayWithObject:doneButton]];

    self.dateToolbar = toolbar;

    self.historyDateSelect.inputView = self.datePicker;
    self.historyDateSelect.inputAccessoryView = self.dateToolbar;

    historyDateSelect.delegate=self;
    
}

- (void)addButtonPressed
{
    self.dateToolbar.hidden=YES;
    self.datePicker.hidden=YES;
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    self.dateToolbar.hidden=NO;
    self.datePicker.hidden=NO;

    return YES;
}

thanks for response
 
Resign First Responder?

Should the datePicker maybe resign first responder?

Code:
[self.datePicker resignFirstResponder];

I know this is true for the keyboard when you are ready to dismiss it. Maybe it's true for the date picker too?
 
Should the datePicker maybe resign first responder?

Code:
[self.datePicker resignFirstResponder];

I know this is true for the keyboard when you are ready to dismiss it. Maybe it's true for the date picker too?

first responder was text field! So it worked when invoked on textfield instance.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.