#import "PickTimeV.h" @interface PickTimeV() { UITableView* myTableView; /**保存那些删除时间段的按钮。数目为defState.planTimes.count; */ NSMutableArray* btns; /**用于动画,不过已废弃。不好看。 */ UIView* centerV; UIButton* btnSt,*btnEnd; UILabel *titleLabel; NSArray *_dataArray; } @end @implementation PickTimeV -(id)init { self = [super initWithFrame:kFrame]; if (self) { _dataArray = [NSArray array]; [self setBackgroundColor:[UIColor colorWithWhite:.01 alpha:.3]]; UIView* aView,*line;UILabel* label; UIButton* btn; CGFloat x,y,w,h,bd; x = y = 0; bd = 10; w = kSize.width - bd*2; h = 40; aView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h*8 + 10)]; aView.center = CGPointMake(kSize.width/2.0, kSize.height/2.0); [self addSubview:aView]; [aView setBackgroundColor:[UIColor whiteColor]]; centerV = aView; y = 0; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)]; [label setText:@"请选择"]; [aView addSubview:label]; [label setTextAlignment:NSTextAlignmentCenter]; titleLabel = label; y += h; line = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, 3)]; [line setBackgroundColor:defGreen]; [aView addSubview:line]; y += 1; h *= 6; UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, y, w, h)]; [tv setDataSource:self]; [tv setDelegate:self]; [aView addSubview:tv]; [tv setTableHeaderView:[UIView new]]; myTableView = tv; y += h; h /=6.0; w = 200; x = (kSize.width - w)*.5; btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y+5, w, h)]; [btn setTitle:@"取消" forState:UIControlStateNormal]; [btn setBackgroundColor:defGreen]; [btn corner:h*.5]; [btn addTarget:self action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; [aView addSubview:btn]; } return self; } -(void)setWhichVC:(NSString *)whichVC { _whichVC = whichVC; if ([whichVC isEqualToString:@"AddRecordVC"]) { titleLabel.text = @"请选择日志类型"; _dataArray = [self getRecordStyle]; } if ([whichVC isEqualToString:@"PostPlanVC2"]) { titleLabel.text = @"请选择训练类型"; _dataArray = [self getExerciseStyle]; } [myTableView reloadData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } NSDictionary* obj = _dataArray[indexPath.row]; if ([_whichVC isEqualToString:@"AddRecordVC"] || [_whichVC isEqualToString:@"PostPlanVC2"]) { [cell.textLabel setText:obj[@"TC_TEACH_TYPE"]]; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (clkBlock) { NSDictionary* obj = _dataArray[indexPath.row]; clkBlock(obj); } [self removeFromSuperview]; } -(void)complete:(MyBlockType)comp { clkBlock = comp; } -(void)show { [[UIApplication sharedApplication].keyWindow addSubview:self]; } -(NSArray *)getRecordStyle { //因为之前的日志页面已经请求过一份了 存入本地 和日志页面同一个plist文件 这里就不去调接口了 如果后期改动 我的想法是 服务器要将之前的改变索引的全改一下 //这一个读取本地的方法 其实可以存userdef的 像其他属性一样 还是算了 //应该是个数组 里边是字典 //allData 从本地获取 不到数据 在这样制造数据 NSMutableArray *array = [NSMutableArray arrayWithObjects:@"车辆基础操作",@"直线控制离合",@"倒车入库左倒",@"倒车入库右倒",@"科目二全套训练",@"预约科目二考试",@"考试日期",@"路跑",@"变更车道",@"会车与超车",@"靠边停车和掉头",@"灯光使用", nil]; NSMutableArray *allData = [NSMutableArray array]; if (allData.count > 0) { [allData removeAllObjects]; } NSString *filePath = [Tools getPathWithFileName:@"getTeachTypes.plist"]; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSArray *arr = [NSArray arrayWithContentsOfFile:filePath]; [allData addObjectsFromArray:arr]; } else { for (int i = 0; i < array.count; i ++) { NSString *KM = @"2"; if (i > 6) { KM = @"3"; } NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:array[i],@"TC_TEACH_TYPE",[NSString stringWithFormat:@"%d",i+1],@"TC_ID",KM,@"TC_SUBJECT", nil]; [allData addObject:dic]; } } NSMutableArray *backArray = [NSMutableArray array]; for (NSDictionary *dic in allData) { if ([dic[@"TC_SUBJECT"] isEqualToString:_KM]) { [backArray addObject:dic]; } if ([_KM isEqualToString:@"23"]) { backArray = allData; } } return backArray; } -(NSArray *)getExerciseStyle { NSMutableArray *array = [NSMutableArray arrayWithObjects:@"倒车入库",@"半坡定点",@"曲线行驶",@"侧方停车",@"直角转弯", nil]; NSMutableArray *allData = [NSMutableArray array]; NSString *filePath = [Tools getPathWithFileName:@"getTypes.plist"]; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSArray *arr = [NSArray arrayWithContentsOfFile:filePath]; [allData addObjectsFromArray:arr]; } else { for (int i = 0; i < array.count; i ++) { NSString *KM = @"2"; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:array[i],@"TC_TEACH_TYPE",[NSString stringWithFormat:@"%d",i+13],@"TC_ID",KM,@"TC_SUBJECT", nil]; [allData addObject:dic]; } } return allData; } @end