【发布时间】:2018-07-21 20:49:24
【问题描述】:
我有一个表格视图,用户可以在其中添加一个包含两个 UITextField 的新行。用户可以使用 UIDatePicker 向每个文本视图添加一个日期(或者不添加一个,将其留空)。完成该过程并保存所有内容后,用户应该能够转到任何行并更新该行中的日期。问题是创建的最后一行之前的任何行仅在需要编辑时才显示常规键盘。除了最后保存的行之外,我似乎无法显示日期选择器。关于为什么会发生这种情况的任何想法?
这是我设置日期选择器的方法:
-(void)showDatePicker{
_datePicker = [[UIDatePicker alloc] init];
UIToolbar *toolbar = [[UIToolbar alloc]init];
[toolbar sizeToFit];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done)];
doneButton.tintColor = [UIColor whiteColor];
UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
toolbar.translucent = YES;
toolbar.barTintColor = [UIColor colorWithRed:8/255.0 green:46/255.0 blue:46/255.0 alpha:1];
[toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft,doneButton ,nil]];
[_readDateCell.startDateTextfield setInputAccessoryView:toolbar];
[_readDateCell.finishDateTextfield setInputAccessoryView:toolbar];
[_datePicker setDatePickerMode:UIDatePickerModeDate];
[_readDateCell.startDateTextfield setInputView:_datePicker];
[_readDateCell.finishDateTextfield setInputView:_datePicker];
}
该函数在两个地方调用 - 当文本字段开始编辑时和正在创建新行时:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[self showDatePicker];
}
-(void)addNewRow {
[self showDatePicker];
}
【问题讨论】:
标签: objective-c uitableview uitextfield uidatepicker custom-cell