BzwPicker.m 25.1 KB
Newer Older
xwenliang's avatar
xwenliang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//
//  BzwPicker.m
//  PickerView
//
//  Created by Bao on 15/12/14.
//  Copyright © 2015年 Microlink. All rights reserved.
//

#import "BzwPicker.h"

@implementation BzwPicker

-(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backArry=[[NSMutableArray alloc]init];
xwenliang's avatar
xwenliang committed
19 20
        self.provinceArray=[[NSMutableArray alloc]init];
        self.cityArray=[[NSMutableArray alloc]init];
xwenliang's avatar
xwenliang committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
        self.selectValueArry=selectValueArry;
        self.pickerDic=dic;
        self.leftStr=leftStr;
        self.rightStr=rightStr;
        self.centStr=centerStr;
        [self getStyle];
        [self getnumStyle];
        dispatch_async(dispatch_get_main_queue(), ^{
           [self makeuiWith:topbgColor With:bottombgColor With:leftbtnbgColor With:rightbtnbgColor With:centerbtnColor];
            [self selectRow];
        });
    }
    return self;
}
-(void)makeuiWith:(NSArray *)topbgColor With:(NSArray *)bottombgColor With:(NSArray *)leftbtnbgColor With:(NSArray *)rightbtnbgColor With:(NSArray *)centerbtnColor
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.frame.size.width, 40)];
    view.backgroundColor = [UIColor cyanColor];
    
    [self addSubview:view];
    
    
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBtn.frame = CGRectMake(10, 5, 50, 30);
    [self.leftBtn setTitle:self.leftStr forState:UIControlStateNormal];
    [self.leftBtn setFont:[UIFont systemFontOfSize:16]];
    self.leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.leftBtn addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self.leftBtn setTitleColor:[self colorWith:leftbtnbgColor] forState:UIControlStateNormal];
    
    [view addSubview:self.leftBtn];
    
    view.backgroundColor=[self colorWith:topbgColor];
    

    self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rightBtn.frame = CGRectMake(view.frame.size.width-60,5, 50, 30);
    [self.rightBtn setTitle:self.rightStr forState:UIControlStateNormal];
    self.rightBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    
    [self.rightBtn setTitleColor:[self colorWith:rightbtnbgColor] forState:UIControlStateNormal];
    
    
    [view addSubview:self.rightBtn];
    [self.rightBtn setFont:[UIFont systemFontOfSize:16]];
    [self.rightBtn addTarget:self action:@selector(cfirmAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *cenLabel=[[UILabel alloc]initWithFrame:CGRectMake(view.frame.size.width/2-25, 5, 50, 30)];
    
    [cenLabel setFont:[UIFont systemFontOfSize:16]];
    
    cenLabel.text=self.centStr;

    [cenLabel setTextColor:[self colorWith:centerbtnColor]];
        
    [view addSubview:cenLabel];

    self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake(-15, 40, self.frame.size.width+15, self.frame.size.height - 40)];
    
    self.pick.delegate = self;
    self.pick.dataSource = self;
    self.pick.showsSelectionIndicator=YES;
    [self addSubview:self.pick];
    
    self.pick.backgroundColor=[self colorWith:bottombgColor];
}
//返回显示的列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    if (_Correlation) {
      //这里是关联的
        if ([_numberCorrela isEqualToString:@"three"]) {
            
            return 3;
            
        }else if ([_numberCorrela isEqualToString:@"two"]){
        
            return 2;
        }
        
    }
    //这里是不关联的
    if (_noArryElementBool) {
        
        return 1;
        
    }else{
        
     return self.noCorreArry.count;
    }
}
//返回当前列显示的行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (_Correlation) {
        
     if (component == 0) {
        
        return self.provinceArray.count;
        
    } else if (component == 1) {
        
        return self.cityArray.count;
        
    } else {
        
        return self.townArray.count;
     }
    }
    
    NSLog(@"%@",[self.noCorreArry objectAtIndex:component]);
    
    if (self.noCorreArry.count==1) {
        
        return [self.noCorreArry count];
        
    }else
    {
        
        if (_noArryElementBool) {
            
            return [self.noCorreArry count];
            
        }
        
     return  [[self.noCorreArry objectAtIndex:component] count];
    }

}

#pragma mark Picker Delegate Methods

//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (_Correlation) {
        
    if (component == 0) {
        
        return [NSString stringWithFormat:@"%@",[self.provinceArray objectAtIndex:row]];
        
    } else if (component == 1) {
        
        return [NSString stringWithFormat:@"%@",[self.cityArray objectAtIndex:row]];
    } else {
        
       return [NSString stringWithFormat:@"%@",[self.townArray objectAtIndex:row]];
      }
    }else{
    
        if (_noArryElementBool) {
            
            return [NSString stringWithFormat:@"%@",[self.noCorreArry objectAtIndex:row]];
            
        }else{
      return [NSString stringWithFormat:@"%@",[[self.noCorreArry objectAtIndex:component] objectAtIndex:row]];
        }
    }
    
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    
    if (_Correlation) {
        return 110;
    }else{
        if (_noArryElementBool) {
            //表示一个数组 特殊情况
            return 110;
        }else{
            
xwenliang's avatar
xwenliang committed
193
            return SCREEN_WIDTH/self.dataDry.count;
xwenliang's avatar
xwenliang committed
194 195 196 197 198 199
        }
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
xwenliang's avatar
xwenliang committed
200 201 202
    if (!row) {
        row=0;
    }
xwenliang's avatar
xwenliang committed
203
    [self.backArry removeAllObjects];
xwenliang's avatar
xwenliang committed
204 205
    [self.infoArry removeAllObjects];
    
xwenliang's avatar
xwenliang committed
206 207 208
    if (_Correlation) {
        //这里是关联的
        
xwenliang's avatar
xwenliang committed
209
        if ([_numberCorrela isEqualToString:@"three"]) {
xwenliang's avatar
xwenliang committed
210
            
xwenliang's avatar
xwenliang committed
211
            if (component == 0)
xwenliang's avatar
xwenliang committed
212
            {
xwenliang's avatar
xwenliang committed
213
                [self.cityArray removeAllObjects];
xwenliang's avatar
xwenliang committed
214
                
xwenliang's avatar
xwenliang committed
215 216 217
                NSInteger setline=[_pick selectedRowInComponent:0];
                
                if (setline) {
xwenliang's avatar
xwenliang committed
218
                    
xwenliang's avatar
xwenliang committed
219
                    self.selectthreeAry =[[self.dataDry objectAtIndex:setline]objectForKey:[self.provinceArray objectAtIndex:setline]];
xwenliang's avatar
xwenliang committed
220 221
                }else{
                    
xwenliang's avatar
xwenliang committed
222
                    setline=0;
xwenliang's avatar
xwenliang committed
223
                    
xwenliang's avatar
xwenliang committed
224
                    self.selectthreeAry =[[self.dataDry objectAtIndex:0] objectForKey:[self.provinceArray objectAtIndex:0]];
xwenliang's avatar
xwenliang committed
225
                }
xwenliang's avatar
xwenliang committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
                
                if (self.selectthreeAry) {
                    //遍历数组
                    for (NSInteger i=0; i<self.selectthreeAry.count; i++) {
                        NSDictionary *dic=self.selectthreeAry[i];
                        NSArray *ary=[dic allKeys];
                        [self.cityArray addObject:[ary firstObject]];
                    }
                }
                else
                {
                    self.cityArray = nil;
                }
                if (self.cityArray.count > 0)
                {
                    
                    self.townArray=[[self.selectthreeAry objectAtIndex:0]objectForKey:[self.cityArray objectAtIndex:0]];
                    
                }
                else
                {
                    self.townArray = nil;
                }
                [pickerView reloadAllComponents];
                [pickerView selectRow:0 inComponent:1 animated:YES];
                [pickerView selectRow:0 inComponent:2 animated:YES];
                
xwenliang's avatar
xwenliang committed
253 254
            }
            
xwenliang's avatar
xwenliang committed
255
            if (component == 1)
xwenliang's avatar
xwenliang committed
256 257
            {
                
xwenliang's avatar
xwenliang committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
                NSInteger setline=[_pick selectedRowInComponent:0];
                
                if (setline) {
                    
                    self.selectthreeAry =[[self.dataDry objectAtIndex:setline]objectForKey:[self.provinceArray objectAtIndex:setline]];
                    
                    NSLog(@"%@",_selectthreeAry);
                    self.townArray=[[self.selectthreeAry  objectAtIndex:row]objectForKey:[self.cityArray objectAtIndex:row]];
                    
                }else{
                    
                    setline=0;
                    
                    self.selectthreeAry =[[self.dataDry objectAtIndex:0] objectForKey:[self.provinceArray objectAtIndex:0]];
                    
                    //NSLog(@"%ld",(long)row);
                    self.townArray=[[self.selectthreeAry objectAtIndex:row]objectForKey:[self.cityArray objectAtIndex:row]];
                }
                
                [pickerView reloadAllComponents];
                [pickerView selectRow:0 inComponent:2 animated:YES];
xwenliang's avatar
xwenliang committed
279 280 281
                
            }
            
xwenliang's avatar
xwenliang committed
282
        }else if ([_numberCorrela isEqualToString:@"two"]){
xwenliang's avatar
xwenliang committed
283
            
xwenliang's avatar
xwenliang committed
284
            if (component == 0)
xwenliang's avatar
xwenliang committed
285
            {
xwenliang's avatar
xwenliang committed
286 287 288 289 290 291 292 293 294 295 296 297
                [self.cityArray removeAllObjects];
                
                self.selectArry =[[self.dataDry objectAtIndex:row]objectForKey:[self.provinceArray objectAtIndex:row]];
                
                if (self.selectArry.count>0) {
                    
                    [self.cityArray addObjectsFromArray:self.selectArry];
                }
                else
                {
                    self.cityArray = nil;
                }
xwenliang's avatar
xwenliang committed
298
            }
xwenliang's avatar
xwenliang committed
299 300
            [pickerView reloadComponent:1];
            [pickerView selectRow:0 inComponent:1 animated:YES];
xwenliang's avatar
xwenliang committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
        }
    }
    //返回选择的值就可以了
    
    if (_Correlation) {
        
        //有关联的,里面有分两种情况
        if ([_numberCorrela isEqualToString:@"three"]) {
            NSString *a=[self.provinceArray objectAtIndex:[self.pick selectedRowInComponent:0]];
            NSString *b=[self.cityArray objectAtIndex:[self.pick selectedRowInComponent:1]];
            NSString *c=[self.townArray objectAtIndex:[self.pick selectedRowInComponent:2]];
            
            [self.backArry addObject:a];
            [self.backArry addObject:b];
            [self.backArry addObject:c];
            
        }else if ([_numberCorrela isEqualToString:@"two"]){
xwenliang's avatar
xwenliang committed
318
            
xwenliang's avatar
xwenliang committed
319 320
            NSString *a=[self.provinceArray objectAtIndex:[self.pick selectedRowInComponent:0]];
            NSString *b=[self.cityArray objectAtIndex:[self.pick selectedRowInComponent:1]];
xwenliang's avatar
xwenliang committed
321
            // NSLog(@"%@---%@",a,b);
xwenliang's avatar
xwenliang committed
322 323 324 325 326 327
            [self.backArry addObject:a];
            [self.backArry addObject:b];
        }
        
    }else
    {
xwenliang's avatar
xwenliang committed
328
        
xwenliang's avatar
xwenliang committed
329 330 331 332 333
        if (_noArryElementBool) {
            
            [self.backArry addObject:[self.noCorreArry objectAtIndex:row]];
            
            
xwenliang's avatar
xwenliang committed
334 335 336 337 338 339 340 341 342 343
        }else{
            //无关联的,直接给三个选项就行
            for (NSInteger i=0; i<self.noCorreArry.count; i++) {
                
                NSArray *eachAry=self.noCorreArry[i];
                
                
                [self.backArry addObject:[eachAry objectAtIndex:[self.pick selectedRowInComponent:i]]];
                
            }
xwenliang's avatar
xwenliang committed
344 345 346 347 348 349 350 351 352 353 354 355 356
        }
    }
    
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    [dic setValue:self.backArry forKey:@"selectedValue"];
    [dic setValue:@"select" forKey:@"type"];
    
    self.bolock(dic);
}
//判断进来的类型是那种
-(void)getStyle
{
    
xwenliang's avatar
xwenliang committed
357 358 359
    self.dataDry=[self.pickerDic objectForKey:@"pickerData"];
    
    id firstobject=[self.dataDry firstObject];
xwenliang's avatar
xwenliang committed
360
    
xwenliang's avatar
xwenliang committed
361
    if ([firstobject isKindOfClass:[NSArray class]]) {
xwenliang's avatar
xwenliang committed
362 363 364
        
        _Correlation=NO;
        
xwenliang's avatar
xwenliang committed
365
    }else if ([firstobject isKindOfClass:[NSDictionary class]]){
xwenliang's avatar
xwenliang committed
366
        
xwenliang's avatar
xwenliang committed
367
        //_Correlation为YES的话是关联的情况 为NO的话 是不关联的情况
xwenliang's avatar
xwenliang committed
368 369
        _Correlation=YES;
        
xwenliang's avatar
xwenliang committed
370
        NSDictionary *dic=(NSDictionary *)firstobject;
xwenliang's avatar
xwenliang committed
371
        
xwenliang's avatar
xwenliang committed
372
        NSArray * twoOrthree=[dic allKeys];
xwenliang's avatar
xwenliang committed
373
        
xwenliang's avatar
xwenliang committed
374 375 376 377
        
        id scendObjct=[[dic objectForKey:[twoOrthree firstObject]] firstObject];
        
        if ([scendObjct isKindOfClass:[NSDictionary class]]) {
xwenliang's avatar
xwenliang committed
378 379 380
            
            _numberCorrela=@"three";
            
xwenliang's avatar
xwenliang committed
381
        }else{
xwenliang's avatar
xwenliang committed
382 383 384 385 386 387
            
            _numberCorrela=@"two";
        }
    }
}
-(void)getnumStyle{
xwenliang's avatar
xwenliang committed
388
    
xwenliang's avatar
xwenliang committed
389 390
    if (_Correlation) {
        
xwenliang's avatar
xwenliang committed
391 392 393 394 395 396 397 398 399 400 401
        //这里是关联的
        if ([_numberCorrela isEqualToString:@"three"]) {
            //省 市
            for (NSInteger i=0; i<self.dataDry.count; i++) {
                
                NSDictionary *dic=[self.dataDry objectAtIndex:i];
                
                NSArray *ary=[dic allKeys];
                
                [self.provinceArray addObject:[ary firstObject]];
            }
xwenliang's avatar
xwenliang committed
402
            
xwenliang's avatar
xwenliang committed
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
            NSDictionary *dic=[self.dataDry firstObject];
            
            NSArray *ary=[dic objectForKey:[self.provinceArray objectAtIndex:0]];
            
            
            if (self.provinceArray.count > 0) {
                
                for (NSInteger i=0; i<ary.count; i++) {
                    
                    NSDictionary *dic=[ary objectAtIndex:i];
                    
                    NSArray *ary=[dic allKeys];
                    
                    [self.cityArray addObject:[ary firstObject]];
                    
                }
            }
xwenliang's avatar
xwenliang committed
420
            
xwenliang's avatar
xwenliang committed
421 422 423 424 425 426 427 428
            if (self.cityArray.count > 0) {
                
                NSDictionary *dic=[ary firstObject];
                
                self.townArray=[dic objectForKey:[self.cityArray firstObject]];
                
            }
        }else if ([_numberCorrela isEqualToString:@"two"]){
xwenliang's avatar
xwenliang committed
429
            
xwenliang's avatar
xwenliang committed
430 431 432 433 434 435 436 437 438
            for (NSInteger i=0; i<self.dataDry.count; i++) {
                
                NSDictionary *dic=[self.dataDry objectAtIndex:i];
                
                NSArray *ary=[dic allKeys];
                
                [self.provinceArray addObject:[ary firstObject]];
            }
            [self.cityArray addObjectsFromArray:[[self.dataDry objectAtIndex:0] objectForKey:[self.provinceArray objectAtIndex:0]]];
xwenliang's avatar
xwenliang committed
439
        }
xwenliang's avatar
xwenliang committed
440 441 442 443
    }else
    {
        //这里是不关联的
        self.noCorreArry=self.dataDry;
xwenliang's avatar
xwenliang committed
444
        
xwenliang's avatar
xwenliang committed
445
        id noArryElement=[self.dataDry firstObject];
xwenliang's avatar
xwenliang committed
446
        
xwenliang's avatar
xwenliang committed
447 448 449 450 451 452 453 454
        if ([noArryElement isKindOfClass:[NSArray class]]) {
            
            _noArryElementBool=NO;
            
        }else{
            //这里为yes表示里面就就一行数据 表示的是只有一行的特殊情况
            _noArryElementBool=YES;
        }
xwenliang's avatar
xwenliang committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
    }
}

//按了取消按钮
-(void)cancleAction
{
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    
    if (self.backArry.count>0) {
        [dic setValue:self.backArry forKey:@"selectedValue"];
        [dic setValue:@"cancel" forKey:@"type"];
        
        self.bolock(dic);
    }else{
        [self getNOselectinfo];
        
        [dic setValue:self.backArry forKey:@"selectedValue"];
        [dic setValue:@"cancel" forKey:@"type"];
        
        self.bolock(dic);
    }
   

    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:.2f animations:^{
            
            [self setFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250)];
            
        }];
    });
}
//按了确定按钮
-(void)cfirmAction
{
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    
    if (self.backArry.count>0) {
        
        [dic setValue:self.backArry forKey:@"selectedValue"];
        [dic setValue:@"confirm" forKey:@"type"];
        
        self.bolock(dic);
        
    }else{
        [self getNOselectinfo];
        [dic setValue:self.backArry forKey:@"selectedValue"];
        [dic setValue:@"confirm" forKey:@"type"];
        
        self.bolock(dic);
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:.2f animations:^{
            
            [self setFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 250)];
        }];
    });
}
-(void)selectRow
{
    if (_Correlation) {
        //关联的一开始的默认选择行数
        if ([_numberCorrela isEqualToString:@"three"]) {
xwenliang's avatar
xwenliang committed
518 519 520
            
            [self selectValueThree];
            
xwenliang's avatar
xwenliang committed
521 522
        }else if ([_numberCorrela isEqualToString:@"two"]){
            
xwenliang's avatar
xwenliang committed
523
            [self selectValueTwo];
xwenliang's avatar
xwenliang committed
524 525 526 527 528 529 530
        }
    }else{
        //一行的时候
        [self selectValueOne];
    }
}
//三行时候的选择哪个的逻辑
xwenliang's avatar
xwenliang committed
531
-(void)selectValueThree
xwenliang's avatar
xwenliang committed
532 533 534 535 536 537
{
    NSString *selectStr=[NSString stringWithFormat:@"%@",self.selectValueArry.firstObject];
    
    for (NSInteger i=0; i<self.provinceArray.count; i++) {
        NSString *str=[NSString stringWithFormat:@"%@",[self.provinceArray objectAtIndex:i]];
        if ([selectStr isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
538
            _num=i;
xwenliang's avatar
xwenliang committed
539 540
            [_pick reloadAllComponents];

xwenliang's avatar
xwenliang committed
541 542 543 544 545
            [_pick selectRow:i  inComponent:0 animated:NO];
            break;
        }
    }
    
xwenliang's avatar
xwenliang committed
546
    NSArray *selecityAry = [[self.dataDry objectAtIndex:_num] objectForKey:selectStr];
xwenliang's avatar
xwenliang committed
547 548 549
    
    if (selecityAry.count>0) {
        
xwenliang's avatar
xwenliang committed
550 551 552 553 554 555 556 557 558 559 560
        [self.cityArray removeAllObjects];
        
        for (NSInteger i=0; i<selecityAry.count; i++) {
            
            NSDictionary *dic=selecityAry[i];
            
            NSArray *ary=[dic allKeys];
            
            [self.cityArray addObject:[ary firstObject]];
            
        }
xwenliang's avatar
xwenliang committed
561 562 563 564 565 566 567 568 569 570
    }
    NSString *selectStrTwo;
    
    if (self.selectValueArry.count>1) {
        selectStrTwo=[NSString stringWithFormat:@"%@",self.selectValueArry[1]];
    }
    for (NSInteger i=0; i<self.cityArray.count; i++) {
        
        NSString *str=[NSString stringWithFormat:@"%@",[self.cityArray objectAtIndex:i]];
        if ([selectStrTwo isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
571 572 573
            
            _threenum=i;
            
xwenliang's avatar
xwenliang committed
574 575
            [_pick reloadAllComponents];

xwenliang's avatar
xwenliang committed
576 577 578 579 580 581
            [_pick selectRow:i  inComponent:1 animated:NO];
            
            break;
        }
    }
    
xwenliang's avatar
xwenliang committed
582
    if (selecityAry.count>0) {
xwenliang's avatar
xwenliang committed
583 584 585
        
        if (self.selectValueArry.count>1) {
            
xwenliang's avatar
xwenliang committed
586 587
            NSArray *arry =[[selecityAry objectAtIndex:_threenum] objectForKey:[self.selectValueArry objectAtIndex:1]];
            
xwenliang's avatar
xwenliang committed
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
            if (arry.count>0) {
                self.townArray=arry;
                
            }
        }
    }
    
    NSString *selectStrThree;
    
    if (self.selectValueArry.count>2) {
        selectStrThree=[NSString stringWithFormat:@"%@",self.selectValueArry[2]];
    }
    for (NSInteger i=0; i<self.townArray.count; i++) {
        
        NSString *str=[NSString stringWithFormat:@"%@",[self.townArray objectAtIndex:i]];
        if ([selectStrThree isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
604 605
            [_pick reloadAllComponents];

xwenliang's avatar
xwenliang committed
606 607 608 609 610 611
            [_pick selectRow:i  inComponent:2 animated:NO];
            break;
        }
    }
}
//两行时候的选择哪个的逻辑
xwenliang's avatar
xwenliang committed
612
-(void)selectValueTwo
xwenliang's avatar
xwenliang committed
613 614 615 616 617 618 619
{
    
    NSString *selectStr=[NSString stringWithFormat:@"%@",self.selectValueArry.firstObject];
    
    for (NSInteger i=0; i<self.provinceArray.count; i++) {
        NSString *str=[NSString stringWithFormat:@"%@",[self.provinceArray objectAtIndex:i]];
        if ([selectStr isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
620
            
xwenliang's avatar
xwenliang committed
621
            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
622
            [_pick selectRow:i  inComponent:0 animated:NO];
xwenliang's avatar
xwenliang committed
623
            _num=i;
xwenliang's avatar
xwenliang committed
624 625 626
            break;
        }
    }
xwenliang's avatar
xwenliang committed
627 628 629 630 631 632
    NSArray *twoArry=[[self.dataDry objectAtIndex:_num]objectForKey:selectStr];
    
    if (twoArry&&twoArry.count>0) {
        
        [self.cityArray removeAllObjects];
        [self.cityArray addObjectsFromArray:twoArry];
xwenliang's avatar
xwenliang committed
633
    }
xwenliang's avatar
xwenliang committed
634
    
xwenliang's avatar
xwenliang committed
635 636
    NSString *selectTwoStr;
    if (self.selectValueArry.count>1) {
xwenliang's avatar
xwenliang committed
637
        
xwenliang's avatar
xwenliang committed
638 639 640 641 642 643
        selectTwoStr =[NSString stringWithFormat:@"%@",[self.selectValueArry objectAtIndex:1]];
    }
    
    for (NSInteger i=0; i<self.cityArray.count; i++) {
        
        NSString *str=[NSString stringWithFormat:@"%@",[self.cityArray objectAtIndex:i]];
xwenliang's avatar
xwenliang committed
644
        
xwenliang's avatar
xwenliang committed
645 646
        if ([selectTwoStr isEqualToString:str]) {
            
xwenliang's avatar
xwenliang committed
647
            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
            [_pick selectRow:i inComponent:1 animated:NO];
            
            break;
        }
    }
}
//一行时候的选择哪个的逻辑
-(void)selectValueOne
{
    if (_noArryElementBool) {
        //这里表示数组里面就只有一个数组 比较特殊的情况[]
        NSString *selectStr;
        if (self.selectValueArry.count>0) {
            
            selectStr=[NSString stringWithFormat:@"%@",[self.selectValueArry firstObject]];
        }
        for (NSInteger i=0; i<self.noCorreArry.count; i++) {
            NSString *str=[NSString stringWithFormat:@"%@",[self.noCorreArry objectAtIndex:i]];
            if ([selectStr isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
667
                [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
                [_pick selectRow:i  inComponent:0 animated:NO];
                break;
            }
        }
        
    }else{
        //这里就比较复杂了 [[],[],[]]
        if (self.selectValueArry.count>0) {
            
            if (self.selectValueArry.count>self.noCorreArry.count) {
                
                for (NSInteger i=0; i<self.noCorreArry.count; i++) {
                    
                    NSString *selectStr=[NSString stringWithFormat:@"%@",[self.selectValueArry objectAtIndex:i]];
                    
                    NSArray *arry=[self.noCorreArry objectAtIndex:i];
                    
                    for (NSInteger j=0; j<arry.count; j++) {
                        
                        NSString *str=[NSString stringWithFormat:@"%@",[arry objectAtIndex:j]];
                        
                        if ([selectStr isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
690
                            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
                            [_pick selectRow:j inComponent:i animated:YES];
                            
                            break;
                        }
                    }
                }
            }else{
                for (NSInteger i=0; i<self.selectValueArry.count; i++) {
                    
                    NSString *selectStr=[NSString stringWithFormat:@"%@",[self.selectValueArry objectAtIndex:i]];
                    
                    NSArray *arry=[self.noCorreArry objectAtIndex:i];
                    
                    for (NSInteger j=0; j<arry.count; j++) {
                        
                        NSString *str=[NSString stringWithFormat:@"%@",[arry objectAtIndex:j]];
                        
                        if ([selectStr isEqualToString:str]) {
xwenliang's avatar
xwenliang committed
709
                            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
                            [_pick selectRow:j inComponent:i animated:YES];
                            
                            break;
                        }
                    }
                }
            }
        }
    }
}
-(void)getNOselectinfo
{
    if (_Correlation) {
        
        //有关联的,里面有分两种情况
        if ([_numberCorrela isEqualToString:@"three"]) {
            NSString *a=[self.provinceArray objectAtIndex:[self.pick selectedRowInComponent:0]];
            NSString *b=[self.cityArray objectAtIndex:[self.pick selectedRowInComponent:1]];
            NSString *c=[self.townArray objectAtIndex:[self.pick selectedRowInComponent:2]];
            
            [self.backArry addObject:a];
            [self.backArry addObject:b];
            [self.backArry addObject:c];
            
        }else if ([_numberCorrela isEqualToString:@"two"]){
            
            NSString *a=[self.provinceArray objectAtIndex:[self.pick selectedRowInComponent:0]];
            NSString *b=[self.cityArray objectAtIndex:[self.pick selectedRowInComponent:1]];
            NSLog(@"%@---%@",a,b);
            [self.backArry addObject:a];
            [self.backArry addObject:b];
        }
        
    }else
    {
        
        if (_noArryElementBool) {
            
            if (self.selectValueArry.count>0) {
                NSString *selectStr=[NSString stringWithFormat:@"%@",[self.selectValueArry firstObject]];
                [self.backArry addObject:selectStr];
            }else{
            
            [self.backArry addObject:[self.noCorreArry objectAtIndex:0]];
            }
            
        }else{
xwenliang's avatar
xwenliang committed
757
            //无关联的,直接给几个选项就行
xwenliang's avatar
xwenliang committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
            for (NSInteger i=0; i<self.noCorreArry.count; i++) {
                
                NSArray *eachAry=self.noCorreArry[i];
                
                [self.backArry addObject:[eachAry objectAtIndex:[self.pick selectedRowInComponent:i]]];
                
            }
        }
    }
}

-(UIColor *)colorWith:(NSArray *)colorArry
{
    NSString *ColorA=[NSString stringWithFormat:@"%@",colorArry[0]];
    NSString *ColorB=[NSString stringWithFormat:@"%@",colorArry[1]];
    NSString *ColorC=[NSString stringWithFormat:@"%@",colorArry[2]];
    NSString *ColorD=[NSString stringWithFormat:@"%@",colorArry[3]];
    
    UIColor *color=[[UIColor alloc]initWithRed:[ColorA integerValue]/255.0 green:[ColorB integerValue]/255.0 blue:[ColorC integerValue]/255.0 alpha:[ColorD floatValue]];
    return color;
}

@end