2013-09-02 7 views
9

Ho un UIDatePicker con date minime e massime. Mi chiedo se c'è un modo per nascondere le righe delle colonne per le date/orari che sono prima della mia data minima o dopo la mia data massima. In questo momento il raccoglitore viene visualizzato ogni singolo giorno ma è disponibile solo la settimana corrente per selezionare (in grassetto), ciò che vorrei è che i numeri al di fuori del range della settimana siano nascosti alla vista. questo può essere fatto con UIDatePicker fornito da XCode o dovrei costruire il mio picker da zero?rimuovere/nascondere le righe al di fuori dell'intervallo di date minimo/massimo di UIDatePicker?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.formatter = [NSDateFormatter new]; 
    [self.formatter setDateFormat:@"dd:hh:mm:ss"]; 

    NSDate *now = [NSDate date]; 

    picker.minimumDate = [NSDate date]; 
    picker.maximumDate = [now dateByAddingTimeInterval:604800]; 

    [picker setDate:now animated:YES]; 
    self.counterLabel.text = [now description]; 

    self.now = [NSDate date]; 
    self.counterLabel.text = [self.formatter stringFromDate:self.now]; 

} 
+0

Sto anche cercando la risposta. Hai trovato qualcosa ... per favore condividi – Sudhir

risposta

2

Utilizzando le API minimumDate e maximumDate si comporterà come hai spiegato - mostrano ancora le date, ma non permettere selezionandoli. Non c'è attualmente alcun modo per nascondere quelle date che sono fuori dalla gamma fornita, tuttavia ho una soluzione per te.

Invece di utilizzare il min e max date con un UIDatePicker, è possibile generare una matrice di tutti i NSDate s che si desidera mostrare all'utente, e utilizzare un UIPickerView per presentarli all'utente. Ho fatto esattamente questo per una delle mie app.

self.datePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 162)]; 
self.datePicker.dataSource = self; 
self.datePicker.delegate = self; 
//... 

#pragma mark - UIPickerView Data Source and Delegate 

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { 
    return 1; 
} 

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 
    return [self.availableDates count]; 
} 

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component { 
    return 28; 
} 

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; 
    label.font = [UIFont systemFontOfSize:20]; 
    label.textColor = [UIColor blackColor]; 

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    dateFormatter.dateFormat = @"EEE, MMMM d"; 

    label.text = [dateFormatter stringFromDate:self.availableDates[row]]; 

    [label sizeToFit]; 

    return label; 
} 
Problemi correlati