1

我正在使用 KIF 在 UIDatePicker 上自动选择日期。如果日期发生变化,我添加了可访问性标签并为选择器设置目标。

参考:http ://bit.ly/140ICwo

+(id) changeDate: (NSDate *) myDate
{

  [s addStep:[KIFTestStep stepToEnterDate:myDate   ToDatePickerWithAccessibilityLabel:@"datePicker"]];
  [self wait:s timeInSeconds:3];
  [s addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Done" traits:UIAccessibilityTraitButton]];
 return s;
}

- (void) ViewDidLoad
{   
    ... 
    datePicker.maximumDate = lastAvailableDate;
    datePicker.date = (dateValue ? dateValue : [NSDate date]);
    [datePicker addTarget:self action:@selector(dateChangedAction:)
     forControlEvents:UIControlEventValueChanged];
    self.datePicker.accessibilityLabel = @"datePicker";
    self.footerLabel.accessibilityLabel = @"datelabel";
}


- (IBAction)dateChangedAction:(id)sender
{
  [dateValue release];
  dateValue = [datePicker.date retain];
  dateCell.detailTextLabel.text = [[[self class] sharedFormatter]  stringFromDate:dateValue];
  [self setDateTitleText:[[[self class] sharedFormatter] stringFromDate:dateValue]];
}

Picker 在给定的日期旋转并停止,但是“dateChangedAction”函数没有被调用,因此显示所选日期的标签没有得到更新。

如果我在没有 KIF 的情况下运行应用程序,一切正常。此外,我尝试在运行 KIF 时手动选择一个日期以检查它是否会更新标签,但似乎 UI 被冻结,我无法单击任何 UI 控件。

看起来问题与此帖子有关

http://bit.ly/10xtbqU

很感谢任何形式的帮助。

谢谢

4

1 回答 1

3

我遇到了你刚刚错过的同样问题

[picker sendActionsForControlEvents:UIControlEventValueChanged];

触发 dateChangedAction 回调,换句话说,试试这个:

+ (id)stepToEnterDate:(NSDate*)date ToDatePickerWithAccessibilityLabel:(NSString*)label
{
    NSString *description=[NSString stringWithFormat:@"Enter date to Date picker with accessibility label '%@'",[date description]];
    return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error)
            {
                UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:label];
                KIFTestCondition(element, error, @"View with label %@ not found", label);
                if(!element)
                {
                    return KIFTestStepResultWait;
                }
                UIDatePicker *picker = (UIDatePicker*)[UIAccessibilityElement viewContainingAccessibilityElement:element];

                KIFTestCondition([picker isKindOfClass:[UIDatePicker class]], error, @"Specified view is not a picker");

                [picker setDate:date animated:YES];

                // trigger the UIControlEventValueChanged in case of event listener
                [picker sendActionsForControlEvents:UIControlEventValueChanged];

                return KIFTestStepResultSuccess;         
            }];
}
于 2014-01-08T20:46:15.260 回答