PickTimeV.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #import "PickTimeV.h"
  2. @interface PickTimeV()<UITableViewDataSource,UITableViewDelegate>
  3. {
  4. UITableView* myTableView;
  5. /**保存那些删除时间段的按钮。数目为defState.planTimes.count;
  6. */
  7. NSMutableArray* btns;
  8. /**用于动画,不过已废弃。不好看。
  9. */
  10. UIView* centerV;
  11. UIButton* btnSt,*btnEnd;
  12. UILabel *titleLabel;
  13. NSArray *_dataArray;
  14. }
  15. @end
  16. @implementation PickTimeV
  17. -(id)init
  18. {
  19. self = [super initWithFrame:kFrame];
  20. if (self) {
  21. _dataArray = [NSArray array];
  22. [self setBackgroundColor:[UIColor colorWithWhite:.01 alpha:.3]];
  23. UIView* aView,*line;UILabel* label; UIButton* btn;
  24. CGFloat x,y,w,h,bd;
  25. x = y = 0;
  26. bd = 10;
  27. w = kSize.width - bd*2;
  28. h = 40;
  29. aView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h*8 + 10)];
  30. aView.center = CGPointMake(kSize.width/2.0, kSize.height/2.0);
  31. [self addSubview:aView];
  32. [aView setBackgroundColor:[UIColor whiteColor]];
  33. centerV = aView;
  34. y = 0;
  35. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  36. [label setText:@"请选择"];
  37. [aView addSubview:label];
  38. [label setTextAlignment:NSTextAlignmentCenter];
  39. titleLabel = label;
  40. y += h;
  41. line = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, 3)];
  42. [line setBackgroundColor:defGreen];
  43. [aView addSubview:line];
  44. y += 1;
  45. h *= 6;
  46. UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, y, w, h)];
  47. [tv setDataSource:self];
  48. [tv setDelegate:self];
  49. [aView addSubview:tv];
  50. [tv setTableHeaderView:[UIView new]];
  51. myTableView = tv;
  52. y += h;
  53. h /=6.0;
  54. w = 200;
  55. x = (kSize.width - w)*.5;
  56. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y+5, w, h)];
  57. [btn setTitle:@"取消" forState:UIControlStateNormal];
  58. [btn setBackgroundColor:defGreen];
  59. [btn corner:h*.5];
  60. [btn addTarget:self action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
  61. [aView addSubview:btn];
  62. }
  63. return self;
  64. }
  65. -(void)setWhichVC:(NSString *)whichVC
  66. {
  67. _whichVC = whichVC;
  68. if ([whichVC isEqualToString:@"AddRecordVC"]) {
  69. titleLabel.text = @"请选择日志类型";
  70. _dataArray = [self getRecordStyle];
  71. }
  72. if ([whichVC isEqualToString:@"PostPlanVC2"]) {
  73. titleLabel.text = @"请选择训练类型";
  74. _dataArray = [self getExerciseStyle];
  75. }
  76. [myTableView reloadData];
  77. }
  78. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  79. {
  80. return _dataArray.count;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  85. if (!cell) {
  86. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  87. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  88. }
  89. NSDictionary* obj = _dataArray[indexPath.row];
  90. if ([_whichVC isEqualToString:@"AddRecordVC"] || [_whichVC isEqualToString:@"PostPlanVC2"]) {
  91. [cell.textLabel setText:obj[@"TC_TEACH_TYPE"]];
  92. }
  93. return cell;
  94. }
  95. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  96. {
  97. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  98. if (clkBlock) {
  99. NSDictionary* obj = _dataArray[indexPath.row];
  100. clkBlock(obj);
  101. }
  102. [self removeFromSuperview];
  103. }
  104. -(void)complete:(MyBlockType)comp
  105. {
  106. clkBlock = comp;
  107. }
  108. -(void)show
  109. {
  110. [[UIApplication sharedApplication].keyWindow addSubview:self];
  111. }
  112. -(NSArray *)getRecordStyle
  113. {
  114. //因为之前的日志页面已经请求过一份了 存入本地 和日志页面同一个plist文件 这里就不去调接口了 如果后期改动 我的想法是 服务器要将之前的改变索引的全改一下
  115. //这一个读取本地的方法 其实可以存userdef的 像其他属性一样 还是算了
  116. //应该是个数组 里边是字典
  117. //allData 从本地获取 不到数据 在这样制造数据
  118. NSMutableArray *array = [NSMutableArray arrayWithObjects:@"车辆基础操作",@"直线控制离合",@"倒车入库左倒",@"倒车入库右倒",@"科目二全套训练",@"预约科目二考试",@"考试日期",@"路跑",@"变更车道",@"会车与超车",@"靠边停车和掉头",@"灯光使用", nil];
  119. NSMutableArray *allData = [NSMutableArray array];
  120. if (allData.count > 0) {
  121. [allData removeAllObjects];
  122. }
  123. NSString *filePath = [Tools getPathWithFileName:@"getTeachTypes.plist"];
  124. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
  125. {
  126. NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
  127. [allData addObjectsFromArray:arr];
  128. }
  129. else
  130. {
  131. for (int i = 0; i < array.count; i ++) {
  132. NSString *KM = @"2";
  133. if (i > 6) {
  134. KM = @"3";
  135. }
  136. NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:array[i],@"TC_TEACH_TYPE",[NSString stringWithFormat:@"%d",i+1],@"TC_ID",KM,@"TC_SUBJECT", nil];
  137. [allData addObject:dic];
  138. }
  139. }
  140. NSMutableArray *backArray = [NSMutableArray array];
  141. for (NSDictionary *dic in allData) {
  142. if ([dic[@"TC_SUBJECT"] isEqualToString:_KM]) {
  143. [backArray addObject:dic];
  144. }
  145. if ([_KM isEqualToString:@"23"]) {
  146. backArray = allData;
  147. }
  148. }
  149. return backArray;
  150. }
  151. -(NSArray *)getExerciseStyle
  152. {
  153. NSMutableArray *array = [NSMutableArray arrayWithObjects:@"倒车入库",@"半坡定点",@"曲线行驶",@"侧方停车",@"直角转弯", nil];
  154. NSMutableArray *allData = [NSMutableArray array];
  155. NSString *filePath = [Tools getPathWithFileName:@"getTypes.plist"];
  156. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
  157. {
  158. NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
  159. [allData addObjectsFromArray:arr];
  160. }
  161. else
  162. {
  163. for (int i = 0; i < array.count; i ++) {
  164. NSString *KM = @"2";
  165. NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:array[i],@"TC_TEACH_TYPE",[NSString stringWithFormat:@"%d",i+13],@"TC_ID",KM,@"TC_SUBJECT", nil];
  166. [allData addObject:dic];
  167. }
  168. }
  169. return allData;
  170. }
  171. @end