1

Action sheet pickerと呼ばれる日付ピッカーを表示するためにこのクラスを使用しています 。私が抱えている問題は、ピッカーの最大日付と最小日付を設定できないことです。

私が使用しているコードは次のとおりです。

tableview didSelectRow メソッドで:

  else if (indexPath.row == 2){
        // here I am using a library which successfully shows a date picker from where we can pick the dates on which we want to request the appt.
        _actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" 
      datePickerMode:UIDatePickerModeTime selectedDate:self.selectedDateandTime 
   target:self action:@selector(dateWasSelected:element:) origin:[self.tableView
  cellForRowAtIndexPath:indexPath]];
        [self.actionSheetPicker addCustomButtonWithTitle:[self.selectedDateandTime 
      getDateStringInFormat:@"dd MMM yyyy"] value:Nil];
        UIDatePicker * picker = (UIDatePicker *)[self.actionSheetPicker 
     configuredPickerView];
        [picker setMinimumDate:self.selectedDateandTime];

        self.actionSheetPicker.hideCancel = NO;
        [self.actionSheetPicker showActionSheetPicker];
}

configuredPickerView メソッドは、次のようなライブラリにあります。

- (UIView *)configuredPickerView {
CGRect datePickerFrame = CGRectMake(0, 40, self.viewSize.width, 216);
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:datePickerFrame];
datePicker.datePickerMode = self.datePickerMode;
[datePicker setDate:self.selectedDate animated:NO];


[datePicker addTarget:self action:@selector(eventForDatePicker:) forControlEvents:UIControlEventValueChanged];

//need to keep a reference to the picker so we can clear the DataSource / Delegate when dismissing (not used in this picker, but just in case somebody uses this as a template for another picker)
self.pickerView = datePicker;

return datePicker;

}

誰かがこの問題について私を助けることができればお願いします. クラスのアーキテクチャを理解するために追加のヘルプが必要な場合は、お気軽にお問い合わせください。

4

2 に答える 2

1

私は同じ問題に直面したので、ActionSheetPicker-3.0にメソッドを書きました。

ActionSheetPicker-3.0これをライブラリに追加します。

// ActionSheetDatePicker.h
+ (id)showPickerWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate target:(id)target action:(SEL)action origin:(id)origin;


// ActionSheetDatePicker.m
+ (id)showPickerWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate target:(id)target action:(SEL)action origin:(id)origin;
{
    ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc] initWithTitle:title datePickerMode:datePickerMode selectedDate:selectedDate target:target action:action origin:origin];
    picker.minimumDate = minimumDate;
    picker.maximumDate = maximumDate;
    [picker showActionSheetPicker];
    return picker;
}

ActionSheetDatePicker を使用する場所にこのコードを記述します

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *maximumDateComponents = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
    [maximumDateComponents setYear:2050];
    NSDate *minDate = [NSDate date];
    NSDate *maxDate = [calendar dateFromComponents:maximumDateComponents];


[ActionSheetDatePicker showPickerWithTitle:@"Select Start Date" datePickerMode:UIDatePickerModeDate selectedDate:[NSDate date] minimumDate:minDate maximumDate:maxDate target:self action:@selector(dateSelected:element:) origin:sender];
于 2015-05-26T09:14:21.830 に答える