即使在iOS 7中从UIDatePicker中选择日期后,UIAlertView按钮也会被禁用

时间:2014-05-30 06:34:08

标签: uialertview uidatepicker ios7.1

问题是从UIDatePicker中选择日期之后" Ok" UIAlertView的按钮被禁用。我试过,但没有运气。

-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView 
每当我们在textfield中输入任何内容时都应该调用

,但是当输入日期时它没有被调用,但是如果我从键盘输入任何内容,那么就可以了。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;
    }
}

1 个答案:

答案 0 :(得分:1)

问题是你没有再调用它来再次验证..插入值后你应该写这行来调用验证..

[alertText sendActionsForControlEvents:UIControlEventEditingChanged];

在你的这种方法中..

- (void)firstTF