#import "PickTimeV.h" #import "Tools.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 = bd = 10; y = 0; 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.layer.masksToBounds = YES; btn.layer.cornerRadius = h*.5; [btn addTarget:self action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; [aView addSubview:btn]; } return self; } -(void)setWhichVC:(NSString *)whichVC { _whichVC = whichVC; if ([whichVC isEqualToString:@"ComplainVC"]) { titleLabel.text = @"请选择投诉类型"; [self getComplainStyle]; }else{ [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; cell.textLabel.font = [UIFont scaleSize:FontTitle]; } NSDictionary* obj = _dataArray[indexPath.row]; if ([_whichVC isEqualToString:@"ComplainVC"]) { [cell.textLabel setText:obj[@"RT_TITLE"]]; } 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]; } -(void)getComplainStyle { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"type" Value:@"2"]; //1 驾校 2教练 NSString* method = @"getComplaintsTypes"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { //NSLog(@"获取投诉类型-->%@---->%@",arr,root); if (!root) { return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } _dataArray = root[@"body"]; [myTableView reloadData]; }]; } @end