cell 中textFile 的inputView inputAccessoryView
来源:互联网 发布:vb select语句使用方法 编辑:程序博客网 时间:2024/05/16 09:51
//在项目中添加了选择生日 ,性别
cell.textField.inputView = self.datePicker;
cell.textField.inputAccessoryView = self.toolbar;
/** DatePicker */
- (void)createTheDatePicker
{
// 选择生日
_datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 200)];
[_datePicker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"]];
_datePicker.backgroundColor = [UIColor whiteColor];
_datePicker.maximumDate = [NSDate date];
[_datePicker setDatePickerMode:UIDatePickerModeDate];
_toolbar = [[UIToolbar alloc]init];
_toolbar.backgroundColor = [UIColor blackColor];//kDefaultColor_separation;
_toolbar.barTintColor =kDefaultColor_sixthree;
_toolbar.frame = CGRectMake(0, 0, KScreenWidth, 40);
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)];
UIBarButtonItem *emptyItem1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *emptyItem2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *comfirmItem = [[UIBarButtonItem alloc]initWithTitle:@"确认" style:UIBarButtonItemStylePlain target:self action:@selector(comfirm:)];
_toolbar.items = @[cancelItem,emptyItem1,emptyItem2, comfirmItem];
}
- (void)cancel:(UIBarButtonItem *)sender{
// 取消 视图消失
[self.view endEditing:YES];
}
- (void)comfirm:(UIBarButtonItem *)sender{
[self.view endEditing:YES];
// 确认 选择日期格式 并 拿到日期
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"yyyy-MM-dd";
NSLog(@"%@",_datePicker.date);
MYLog(@"%@",[formatter stringFromDate:_datePicker.date]);
// self.textField.text =[formatter stringFromDate:_datePicker.date];
NSCalendar *calendar = [NSCalendar currentCalendar];//定义一个NSCalendar对象
NSDate *nowDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
//生日
NSDate *birthDay = _datePicker.date;//[dateFormatter dateFromString:birth];
//用来得到详细的时差
unsigned int unitFlags = kCFCalendarUnitYear | kCFCalendarUnitMonth | kCFCalendarUnitDay | kCFCalendarUnitHour | kCFCalendarUnitMinute | kCFCalendarUnitSecond;
NSDateComponents *date = [calendar components:unitFlags fromDate:birthDay toDate:nowDate options:0];
NSString *ageTemp;
if([date year] >0)
{
NSLog(@"%@",[NSString stringWithFormat:(@"%ld岁%ld月%ld天"),(long)[date year],(long)[date month],(long)[date day]]) ;
ageTemp = [NSString stringWithFormat:@"%ld岁",(long)[date year]];
}
else if([date month] >0)
{
NSLog(@"%@",[NSString stringWithFormat:(@"%ld月%ld天"),(long)[date month],(long)[date day]]);
ageTemp = [NSString stringWithFormat:@"%ld个月",(long)[date month]];
}
else if([date day]>0){
NSLog(@"%@",[NSString stringWithFormat:(@"%ld天"),(long)[date day]]);
ageTemp = [NSString stringWithFormat:@"%ld天",(long)[date day]];
}
else {
NSLog(@"0天");
ageTemp = @"0岁";
}
//年龄更新
CDOpenCountModel *ageModel = self.dataArray[1];
ageModel.content = ageTemp;
[self.dataArray replaceObjectAtIndex:1 withObject:ageModel];
NSIndexPath *pathAge = [NSIndexPath indexPathForRow:1 inSection:0];
//出生日期更新
CDOpenCountModel *birthdayModel = self.dataArray[2];
birthdayModel.content = [formatter stringFromDate:_datePicker.date];;
[self.dataArray replaceObjectAtIndex:2 withObject:birthdayModel];
NSIndexPath *pathBir = [NSIndexPath indexPathForRow:2 inSection:0];
[self.tableView reloadRowsAtIndexPaths:@[pathAge,pathBir] withRowAnimation:UITableViewRowAnimationNone];
// [self.textField endEditing:YES];
}
/** DatePicker */
- (void)createTheSixPicker
{
// 选择性别
_sixPicker = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 200)];
_sixPicker.dataSource = self;
_sixPicker.delegate = self;
_sixPicker.backgroundColor = [UIColor whiteColor];
_sixToolbar = [[UIToolbar alloc]init];
_sixToolbar.backgroundColor = [UIColor blackColor];
_sixToolbar.barTintColor = kDefaultColor_sixthree;
_sixToolbar.frame = CGRectMake(0, 0, KScreenWidth, 40);
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelSix:)];
UIBarButtonItem *emptyItem1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *emptyItem2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *comfirmItem = [[UIBarButtonItem alloc]initWithTitle:@"确认" style:UIBarButtonItemStylePlain target:self action:@selector(comfirmSix:)];
_sixToolbar.items = @[cancelItem,emptyItem1,emptyItem2, comfirmItem];
}
- (void)cancelSix:(UIBarButtonItem *)sender{
// 取消 视图消失
[self.view endEditing:YES];
}
- (void)comfirmSix:(UIBarButtonItem *)sender{
// 确认
//年龄更新
CDOpenCountModel *sixModel = self.dataArray[3];
NSIndexPath *pathSix = [NSIndexPath indexPathForRow:3 inSection:0];
if ([self.sixPicker selectedRowInComponent:0] == 0) {
//self.textField.text = @"男";
sixModel.content = @"男";
[self.dataArray replaceObjectAtIndex:3 withObject:sixModel];
[self.tableView reloadRowsAtIndexPaths:@[pathSix] withRowAnimation:UITableViewRowAnimationNone];
}else{
// self.textField.text = @"女";
sixModel.content = @"女";
[self.dataArray replaceObjectAtIndex:3 withObject:sixModel];
[self.tableView reloadRowsAtIndexPaths:@[pathSix] withRowAnimation:UITableViewRowAnimationNone];
}
[self.view endEditing:YES];
}
****注意一个坑,cell复用的时候,键盘的样式也会复用
不用的时候添加一句
cell.textField.inputView = nil;
cell.textField.inputAccessoryView = nil;
- cell 中textFile 的inputView inputAccessoryView
- inputAccessoryView和inputView的区别
- inputAccessoryView,inputView
- inputAccessoryView,inputView
- iOS UITextField InputAccessoryView & InputView的使用方法
- UIResponder inputView与inputAccessoryView
- UIButton中的inputAccessoryView,inputView
- iOS inputView 和 inputAccessoryView
- InputAccessoryView 与 inputView理解
- inputView与inputAccessoryView
- keyboard监听、inputView、inputAccessoryView
- ios开发-inputView和inputAccessoryView
- iOS开发inputView和inputAccessoryView
- inputView与inputAccessoryView的使用,即自定义控件的响应视图
- IOS学习笔记(六)inputAccessoryView,inputView
- IOS学习笔记(六)inputAccessoryView,inputView
- IOS学习笔记(六)inputAccessoryView,inputView
- 【iOS开发-70】点菜系统案例:利用文本框的inputView和inputAccessoryView串联UIPickerView、UIDatePicker和UIToolBar
- Android 2D绘图(Canvas+paint)详解
- 苹果开发者身份分类的区别
- Android PopupWindow的使用技巧
- CocoaPods安装教程
- 0904 Java 抽象类经典例子3
- cell 中textFile 的inputView inputAccessoryView
- 网络监控软件:国产化VS外来者
- shell脚本实现sequoiadb数据导出功能
- js异步加载的三种解决方案
- socket通信简介
- 给 Android 开发者的 RxJava 详解
- 算法以及数据结构(上)
- 【机器学习自学笔记1】 从机器学习谈起
- 谈冒烟测试