EAActionSheetPicker不显示时间选择器

时间:2013-08-05 08:16:04

标签: ios uipickerview uidatepicker uiactionsheet

我使用此自定义类EAActionSheetPicker来创建和显示带有日期选择器的动作表,以及第二个用于时间的动作表。

以下屏幕是此视图的故事板:

enter image description here

所以很简单 - 当我点击结束日期按钮时,它应该显示带有日期选择器的操作表。类似地,当我点击时间按钮时,它应该只显示时间选择器,但它显示带有日期的选择器(与结束日期相同)。 但是奇怪的事情发生在EAActionSheetPicker委托方法中:EAActionSheetPicker:didDismissWithSelection:inTextField:textField - 我确定选择器是处于日期还是时间模式,并为每个人记录正确的值(下面的代码)。

- (IBAction)endDateSelectionButton:(UIButton *)sender
{
    // Initialization of custom date picker
    self.endDatePicker = [[EAActionSheetPicker alloc] initWithDatePickerMode:UIDatePickerModeDate];

    // Setting style for action sheet
    [self.endDatePicker setActionSheetStyle:UIActionSheetStyleBlackOpaque];

    // Setting data mode for picker to be only date without time
    [self.endDatePicker setDateMode:UIDatePickerModeDate];

    // Uncomment this if you ever want a title
    // [self.endDatePicker setTitle:@"Choose end date"];

    self.endDatePicker.delegate = self;

    // Showing in superview because of the tab bar controller
    [self.endDatePicker showInView:[self.view superview]];
}

// Something doesn't work with time mode
- (IBAction)timeSelectionButton:(UIButton *)sender
{
    self.timePicker = [[EAActionSheetPicker alloc] initWithDatePickerMode:UIDatePickerModeTime];
    [self.timePicker setActionSheetStyle:UIActionSheetStyleBlackOpaque];
    [self.timePicker setDateMode:UIDatePickerModeTime];

    self.timePicker.delegate = self;
    [self.timePicker showInView:[self.view superview]];
}

// Delegates method for getting picked date
- (void)EAActionSheetPicker:(EAActionSheetPicker *)actionSheet didDismissWithSelection:(id)selection inTextField:(UITextField *)textField
{
    // Determining if action sheet date mode is date or time for new project options
    if (actionSheet.dateMode == UIDatePickerModeDate) {
        // Init date formatter for changing the date output for database
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        // Setting data format to be: day-month-year
        [formatter setDateFormat:@"dd-MM-yyyy"];
        NSString *endDate = [formatter stringFromDate:selection];
        self.endDate = selection;

        // Setting button title to display selected date
        [self.endDateButton setTitle:endDate forState:UIControlStateNormal];
    } else if (actionSheet.dateMode == UIDatePickerModeTime) {
        NSLog(@"TIME...");
    }
}

1 个答案:

答案 0 :(得分:0)

我在EAActionStyleSheet原始代码中发现了错误,并将其更改为对我自己。