You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
6.9 KiB

//
// NewOrdinaryTableViewCell.m
// tongxin
//
// Created by WeiChaoZheng on 2018/9/30.
// Copyright © 2018xTT. All rights reserved.
//
#import "NewOrdinaryTableViewCell.h"
#import "User.h"
@interface NewOrdinaryTableViewCell()<UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>
{
NSInteger _startNum;
NSInteger _endNum;
NSInteger _nowIndex;
}
@property (assign, nonatomic) NSString *regularStr;
//@property (strong, nonatomic)NSArray *imageNameArr;
@end
@implementation NewOrdinaryTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
self.selectionStyle = UITableViewCellSelectionStyleNone;
//取消 输入回调
[self.aTextField addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventEditingChanged];
self.contactImageView.hidden = YES;
self.contactImageView.layer.cornerRadius = self.contactImageView.frame.size.height/2;
self.contactImageView.layer.masksToBounds = YES;
self.contactLabel.hidden = YES;
self.aTextField.hidden = NO;
self.lineView.backgroundColor = RGB(248, 248, 248);
self.aTextField.font = DefineFontSize;
self.aTitleLabel.font = DefineFontSize;
self.contactLabel.font = DefineFontSize;
}
- (void)setDevice:(Device *)device{
_device = device;
// self.contactImageView.image = [UIImage imageNamed:self.imageNameArr[device.relationship_image_id.intValue-1]];
self.contactImageView.image = [myHelper getClickRelationshipImageWithCodeID:[device.relationship_image_id intValue] > 3 ? 2 : [device.relationship_image_id intValue] deviceType:self.deviceType.integerValue];
self.contactLabel.text = device.relationship;
self.contactImageView.hidden = NO;
self.contactLabel.hidden = NO;
self.aTextField.hidden = YES;
}
- (void)defaultInputView{
self.aTextField.inputView = nil;
self.aTextField.delegate = nil;
}
- (void)timeInputViewWithModel:(UIDatePickerMode)mode WithData:(NSDate *)nowDate{
self.aTextField.textAlignment = NSTextAlignmentRight;
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = mode;
datePicker.date = nowDate;
// datePicker.datePickerMode = UIDatePickerModeTime;
if (@available(iOS 13.4, *)) {
datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
}
[datePicker addTarget:self
action:@selector(cellClick:)
forControlEvents:UIControlEventValueChanged];
self.aTextField.inputView = datePicker;
self.aTextField.delegate = self;
}
- (void)numberInputViewWithStartNum:(NSInteger)startNum EndNum:(NSInteger)endNum WithIndex:(NSInteger)nowIndex{
UIPickerView *numberPickerView = [UIPickerView new];
numberPickerView.delegate = self;
numberPickerView.dataSource = self;
_endNum = endNum;
_startNum = startNum;
_nowIndex = nowIndex;
int temp = (int)(nowIndex - _startNum);
if(temp < 0){
temp = 0;
}
[numberPickerView selectRow:temp inComponent:0 animated:NO];
self.aTextField.inputView = numberPickerView;
self.aTextField.delegate = self;
}
#pragma mark UIPickerViewDataSource 数据源方法
// 返回多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// 返回多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return _endNum-_startNum;
}
#pragma mark UIPickerViewDelegate 代理方法
// 返回每行的标题
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(_startNum == -1 && _endNum == 1){ //是否是性别的配置
return (row == 0) ? @"女孩" : @"男孩";
}
return [NSString stringWithFormat:@"%d",_startNum+row];
}
// 选中行显示在label上
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (self.block) {
if(_startNum == -1 && _endNum == 1){ //是否是性别的配置
self.block ([NSString stringWithFormat:@"%d",row],self);
}else{
self.block ([NSString stringWithFormat:@"%d",_startNum+row],self);
}
}
}
- (void)cellClick:(id)sender{
if (self.block) {
if ([sender isKindOfClass:[UITextField class]]) {
UITextField *textField = sender;
if (textField.keyboardType == UIKeyboardTypePhonePad) {
NSString *tmp = textField.text;
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789-"] invertedSet];
textField.text = [[tmp componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
}
self.block (textField.text,self);
return;
}
if([sender isKindOfClass:[UIDatePicker class]]){
UIDatePicker * datePic = (UIDatePicker*)sender;
if (datePic.datePickerMode == UIDatePickerModeTime){ //时间
NSString *text = [myHelper getDateFormatWithStr:@"HH:mm"
date:[datePic date]];
self.aTextField.text = text;
self.block(text,self);
return;
}else if (datePic.datePickerMode == UIDatePickerModeDate){//日期
NSString *text = [myHelper getDateFormatWithStr:@"yyyy-MM-dd"
date:[datePic date]];
self.aTextField.text = text;
self.block(text,self);
return;
}
}
}
}
//MARK: UITextFieldDelegate
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
if ([textField.inputView isKindOfClass:[UIDatePicker class]]) {
UIDatePicker *datePicker = (UIDatePicker *)textField.inputView;
if (datePicker.datePickerMode == UIDatePickerModeTime){ //时间
NSString *text = [myHelper getDateFormatWithStr:@"HH:mm"
date:[datePicker date]];
textField.text = text;
self.block(text,self);
}else if (datePicker.datePickerMode == UIDatePickerModeDate){//日期
NSString *text = [myHelper getDateFormatWithStr:@"yyyy-MM-dd"
date:[datePicker date]];
textField.text = text;
self.block(text,self);
}
}
return YES;
}
#pragma mark 正则表达式判断
-(BOOL)validateNumber:(NSString *)text
{
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",self.regularStr];
return [numberPre evaluateWithObject:text];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end