2013-08-05 80 views
0

我使用此自定義類EAActionSheetPicker創建和顯示操作表,其中包含日期選擇器和第二個時間操作表。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..."); 
    } 
} 

回答

0

我發現EAActionStyleSheet原代碼的bug和chenge它是爲自己正確的。

相關問題