1

The problem is that after picking date from UIDatePicker the "Ok" button of UIAlertView is disabled.I tried ,but no luck.

-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView 

should be called whenever we type anything in textfield,but when date is entered it's not getting called,but if i type anything from keyboard,its ok then.

enter image description here

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0 && indexPath.row == 1)
       {
        alertView1 = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done",nil];
        alertView1.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        alertView1.tag=1;
        alertText = [alertView1 textFieldAtIndex:0];
        itemText = [alertView1 textFieldAtIndex:1];
                alertText.inputView=datePicker;
        itemText.inputView=secondPicker;
        [datePicker addTarget:self action:@selector(firstTF) forControlEvents:UIControlEventValueChanged];
        [secondPicker addTarget:self action:@selector(secondTF) forControlEvents:UIControlEventValueChanged];
        [alertText setPlaceholder:@"From Date"];
        [itemText setPlaceholder:@"To Date"];
        itemText.secureTextEntry = NO;
        [alertView1 show];
}

- (void)firstTF
{
    NSDate *date = datePicker.date;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateStyle:NSDateFormatterMediumStyle];
    alertText.text = [dateFormat stringFromDate:date];
}

- (void)secondTF
 {
    NSDate *date = secondPicker.date;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateStyle:NSDateFormatterMediumStyle];
    itemText.text = [dateFormat stringFromDate:date];
 }


- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
 {
    NSString *inputText = [[alertView textFieldAtIndex:0] text];

    if( [inputText length] > 0)
    {
         NSLog(@"alertViewShouldEnableFirstOtherButton: was called!");
         return YES;
    }
    else
    {
        return NO;
    }
}
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
Nilesh Kumar
  • 2,141
  • 3
  • 16
  • 20

1 Answers1

0

This happens because of "alertViewShouldEnableFirstOtherButton" called before you enter the text in to text field. As per your condition in side the method "Done" button will be disable. Remove this method and you will achieve your target.

Rinku
  • 910
  • 13
  • 28