iOS pokazuje UIPickerView między UITableViewCells
W systemie iOS 7 deweloperzy są zachęcani do pokazywania selektorów dat między komórkami tabeli, gdy są potrzebne do wprowadzenia danych, a następnie ukrywania ich po zakończeniu. Jak mogę osiągnąć ten efekt?
1 answers
Vasilica Costescu ma świetny tutorial na ten temat tutaj: http://masteringios.com/blog/2013/10/31/ios-7-in-line-uidatepicker/
I dla tabel statycznych: http://masteringios.com/blog/2013/11/18/ios-7-in-line-uidatepicker-part-2/
Przykładowy kod tutaj: https://github.com/costescv/InlineDatePicker
Kluczowymi bitami są metody hide / show:
- (void)showDatePickerCell {
self.datePickerIsShowing = YES;
[self.tableView beginUpdates];
[self.tableView endUpdates];
self.datePicker.hidden = NO;
self.datePicker.alpha = 0.0f;
[UIView animateWithDuration:0.25 animations:^{
self.datePicker.alpha = 1.0f;
}];
}
- (void)hideDatePickerCell {
self.datePickerIsShowing = NO;
[self.tableView beginUpdates];
[self.tableView endUpdates];
[UIView animateWithDuration:0.25
animations:^{
self.datePicker.alpha = 0.0f;
}
completion:^(BOOL finished){
self.datePicker.hidden = YES;
}];
}
I ta metoda UITableViewDelegate "ukryje" wiersz, ustawiając jego wysokość na 0 :
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 4 && self.datePickerIsShowing == NO){
// hide date picker row
return 0.0f;
}
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
Metody Ukryj / pokaż można wywołać za pomocą przycisku lub po prostu wybierając wiersze w tabeli. (Uwaga: jeśli w pozostałych wierszach znajdują się pola tekstowe, może być konieczne ukrycie datePicker w metodzie delegata textFieldDidBeginEditing).
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 4) {
if (self.datePickerIsShowing){
[self hideDatePickerCell];
}else {
[self showDatePickerCell];
}
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
EDIT: uważaj, używając więcej niż kilku widoków selektora inline w jednej tabeli. Zauważyłem, że ładują się bardzo powoli ze storyboardów: iOS 7 powoli, aby otworzyć UITableViewController z UIPickerView
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:34:14