【问题标题】:UIAlertView button is disabled even after picking date from UIDatePicker即使在从 UIDatePicker 选择日期之后,UIAlertView 按钮也被禁用
【发布时间】:2014-05-29 10:11:33
【问题描述】:

问题是从 UIDatePicker 选择日期后,UIAlertView 的“确定”按钮被禁用。我试过了,但没有运气。

-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView 

当我们在文本字段中输入任何内容时都应该调用它,但是当输入日期时它不会被调用,但是如果我从键盘输入任何内容,那么就可以了。

- (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;
    }
}

【问题讨论】:

    标签: ios7 uialertview uidatepicker uialertviewdelegate


    【解决方案1】:

    这是因为在您将文本输入到文本字段之前调用了“alertViewShouldEnableFirstOtherButton”。根据您的情况,方法“完成”按钮将被禁用。删除此方法,您将实现目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多