设置软键盘为时间选择器

一、设置软键盘为时间选择器

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.indexPath = indexPath;
//获取当前点击的cell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//为了点击cell的时候能弹出键盘
//生成文本框,并且让文本框成为第一响应者
UITextField *txt = [UITextField new];
[cell addSubview:txt];

//设置键盘的工具栏
CZKeyboard *tool = [CZKeyboard keyboardTool];
tool.delegate = self;
txt.inputAccessoryView = tool;


//弹出datePicker
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
self.datePicker = datePicker;
datePicker.datePickerMode = UIDatePickerModeTime;
datePicker.backgroundColor = [UIColor lightGrayColor];

//把弹出键盘改成datePicker
txt.inputView = datePicker;

//让文本框成为第一响应者,此处之前 应该先设置inputView
[txt becomeFirstResponder];
}

你可能感兴趣的:(设置软键盘为时间选择器)