BzwPicker.m 25.3 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
        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];
xwenliang's avatar
xwenliang committed
44
    self.leftBtn.frame = CGRectMake(10, 5, 90, 30);
xwenliang's avatar
xwenliang committed
45 46 47 48 49 50 51 52 53 54 55 56 57
    [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];
xwenliang's avatar
xwenliang committed
58
     self.rightBtn.frame = CGRectMake(view.frame.size.width-100,5, 90, 30);
xwenliang's avatar
xwenliang committed
59 60 61 62 63 64 65 66 67 68 69
    [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];
    
    
xwenliang's avatar
xwenliang committed
70 71 72
    UILabel *cenLabel=[[UILabel alloc]initWithFrame:CGRectMake(90, 5, SCREEN_WIDTH-180, 30)];
    
    cenLabel.textAlignment=NSTextAlignmentCenter;
xwenliang's avatar
xwenliang committed
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
    
    [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) {
xwenliang's avatar
xwenliang committed
188 189 190 191 192 193
        if ([_numberCorrela isEqualToString:@"three"]) {
            
            return SCREEN_WIDTH/3;
        }else{
            return SCREEN_WIDTH/2;
        }
xwenliang's avatar
xwenliang committed
194 195 196
    }else{
        if (_noArryElementBool) {
            //表示一个数组 特殊情况
xwenliang's avatar
xwenliang committed
197
            return SCREEN_WIDTH;
xwenliang's avatar
xwenliang committed
198 199
        }else{
            
xwenliang's avatar
xwenliang committed
200
            return SCREEN_WIDTH/self.dataDry.count;
xwenliang's avatar
xwenliang committed
201 202 203 204 205 206
        }
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
xwenliang's avatar
xwenliang committed
207 208 209
    if (!row) {
        row=0;
    }
xwenliang's avatar
xwenliang committed
210
    [self.backArry removeAllObjects];
xwenliang's avatar
xwenliang committed
211 212
    [self.infoArry removeAllObjects];
    
xwenliang's avatar
xwenliang committed
213 214 215
    if (_Correlation) {
        //这里是关联的
        
xwenliang's avatar
xwenliang committed
216
        if ([_numberCorrela isEqualToString:@"three"]) {
xwenliang's avatar
xwenliang committed
217
            
xwenliang's avatar
xwenliang committed
218
            if (component == 0)
xwenliang's avatar
xwenliang committed
219
            {
xwenliang's avatar
xwenliang committed
220
                [self.cityArray removeAllObjects];
xwenliang's avatar
xwenliang committed
221
                
xwenliang's avatar
xwenliang committed
222 223 224
                NSInteger setline=[_pick selectedRowInComponent:0];
                
                if (setline) {
xwenliang's avatar
xwenliang committed
225
                    
xwenliang's avatar
xwenliang committed
226
                    self.selectthreeAry =[[self.dataDry objectAtIndex:setline]objectForKey:[self.provinceArray objectAtIndex:setline]];
xwenliang's avatar
xwenliang committed
227 228
                }else{
                    
xwenliang's avatar
xwenliang committed
229
                    setline=0;
xwenliang's avatar
xwenliang committed
230
                    
xwenliang's avatar
xwenliang committed
231
                    self.selectthreeAry =[[self.dataDry objectAtIndex:0] objectForKey:[self.provinceArray objectAtIndex:0]];
xwenliang's avatar
xwenliang committed
232
                }
xwenliang's avatar
xwenliang committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
                
                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
260 261
            }
            
xwenliang's avatar
xwenliang committed
262
            if (component == 1)
xwenliang's avatar
xwenliang committed
263 264
            {
                
xwenliang's avatar
xwenliang committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
                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
286 287 288
                
            }
            
xwenliang's avatar
xwenliang committed
289
        }else if ([_numberCorrela isEqualToString:@"two"]){
xwenliang's avatar
xwenliang committed
290
            
xwenliang's avatar
xwenliang committed
291
            if (component == 0)
xwenliang's avatar
xwenliang committed
292
            {
xwenliang's avatar
xwenliang committed
293 294 295 296 297 298 299 300 301 302 303 304
                [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
305
            }
xwenliang's avatar
xwenliang committed
306 307
            [pickerView reloadComponent:1];
            [pickerView selectRow:0 inComponent:1 animated:YES];
xwenliang's avatar
xwenliang committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
        }
    }
    //返回选择的值就可以了
    
    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
325
            
xwenliang's avatar
xwenliang committed
326 327
            NSString *a=[self.provinceArray objectAtIndex:[self.pick selectedRowInComponent:0]];
            NSString *b=[self.cityArray objectAtIndex:[self.pick selectedRowInComponent:1]];
xwenliang's avatar
xwenliang committed
328
            // NSLog(@"%@---%@",a,b);
xwenliang's avatar
xwenliang committed
329 330 331 332 333 334
            [self.backArry addObject:a];
            [self.backArry addObject:b];
        }
        
    }else
    {
xwenliang's avatar
xwenliang committed
335
        
xwenliang's avatar
xwenliang committed
336 337 338 339 340
        if (_noArryElementBool) {
            
            [self.backArry addObject:[self.noCorreArry objectAtIndex:row]];
            
            
xwenliang's avatar
xwenliang committed
341 342 343 344 345 346 347 348 349 350
        }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
351 352 353 354 355 356 357 358 359 360 361 362 363
        }
    }
    
    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
364 365 366
    self.dataDry=[self.pickerDic objectForKey:@"pickerData"];
    
    id firstobject=[self.dataDry firstObject];
xwenliang's avatar
xwenliang committed
367
    
xwenliang's avatar
xwenliang committed
368
    if ([firstobject isKindOfClass:[NSArray class]]) {
xwenliang's avatar
xwenliang committed
369 370 371
        
        _Correlation=NO;
        
xwenliang's avatar
xwenliang committed
372
    }else if ([firstobject isKindOfClass:[NSDictionary class]]){
xwenliang's avatar
xwenliang committed
373
        
xwenliang's avatar
xwenliang committed
374
        //_Correlation为YES的话是关联的情况 为NO的话 是不关联的情况
xwenliang's avatar
xwenliang committed
375 376
        _Correlation=YES;
        
xwenliang's avatar
xwenliang committed
377
        NSDictionary *dic=(NSDictionary *)firstobject;
xwenliang's avatar
xwenliang committed
378
        
xwenliang's avatar
xwenliang committed
379
        NSArray * twoOrthree=[dic allKeys];
xwenliang's avatar
xwenliang committed
380
        
xwenliang's avatar
xwenliang committed
381 382 383 384
        
        id scendObjct=[[dic objectForKey:[twoOrthree firstObject]] firstObject];
        
        if ([scendObjct isKindOfClass:[NSDictionary class]]) {
xwenliang's avatar
xwenliang committed
385 386 387
            
            _numberCorrela=@"three";
            
xwenliang's avatar
xwenliang committed
388
        }else{
xwenliang's avatar
xwenliang committed
389 390 391 392 393 394
            
            _numberCorrela=@"two";
        }
    }
}
-(void)getnumStyle{
xwenliang's avatar
xwenliang committed
395
    
xwenliang's avatar
xwenliang committed
396 397
    if (_Correlation) {
        
xwenliang's avatar
xwenliang committed
398 399 400 401 402 403 404 405 406 407 408
        //这里是关联的
        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
409
            
xwenliang's avatar
xwenliang committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
            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
427
            
xwenliang's avatar
xwenliang committed
428 429 430 431 432 433 434 435
            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
436
            
xwenliang's avatar
xwenliang committed
437 438 439 440 441 442 443 444 445
            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
446
        }
xwenliang's avatar
xwenliang committed
447 448 449 450
    }else
    {
        //这里是不关联的
        self.noCorreArry=self.dataDry;
xwenliang's avatar
xwenliang committed
451
        
xwenliang's avatar
xwenliang committed
452
        id noArryElement=[self.dataDry firstObject];
xwenliang's avatar
xwenliang committed
453
        
xwenliang's avatar
xwenliang committed
454 455 456 457 458 459 460 461
        if ([noArryElement isKindOfClass:[NSArray class]]) {
            
            _noArryElementBool=NO;
            
        }else{
            //这里为yes表示里面就就一行数据 表示的是只有一行的特殊情况
            _noArryElementBool=YES;
        }
xwenliang's avatar
xwenliang committed
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 518 519 520 521 522 523 524
    }
}

//按了取消按钮
-(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
525 526 527
            
            [self selectValueThree];
            
xwenliang's avatar
xwenliang committed
528 529
        }else if ([_numberCorrela isEqualToString:@"two"]){
            
xwenliang's avatar
xwenliang committed
530
            [self selectValueTwo];
xwenliang's avatar
xwenliang committed
531 532 533 534 535 536 537
        }
    }else{
        //一行的时候
        [self selectValueOne];
    }
}
//三行时候的选择哪个的逻辑
xwenliang's avatar
xwenliang committed
538
-(void)selectValueThree
xwenliang's avatar
xwenliang committed
539 540 541 542 543 544
{
    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
545
            _num=i;
xwenliang's avatar
xwenliang committed
546 547
            [_pick reloadAllComponents];

xwenliang's avatar
xwenliang committed
548 549 550 551 552
            [_pick selectRow:i  inComponent:0 animated:NO];
            break;
        }
    }
    
xwenliang's avatar
xwenliang committed
553
    NSArray *selecityAry = [[self.dataDry objectAtIndex:_num] objectForKey:selectStr];
xwenliang's avatar
xwenliang committed
554 555 556
    
    if (selecityAry.count>0) {
        
xwenliang's avatar
xwenliang committed
557 558 559 560 561 562 563 564 565 566 567
        [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
568 569 570 571 572 573 574 575 576 577
    }
    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
578 579 580
            
            _threenum=i;
            
xwenliang's avatar
xwenliang committed
581 582
            [_pick reloadAllComponents];

xwenliang's avatar
xwenliang committed
583 584 585 586 587 588
            [_pick selectRow:i  inComponent:1 animated:NO];
            
            break;
        }
    }
    
xwenliang's avatar
xwenliang committed
589
    if (selecityAry.count>0) {
xwenliang's avatar
xwenliang committed
590 591 592
        
        if (self.selectValueArry.count>1) {
            
xwenliang's avatar
xwenliang committed
593 594
            NSArray *arry =[[selecityAry objectAtIndex:_threenum] objectForKey:[self.selectValueArry objectAtIndex:1]];
            
xwenliang's avatar
xwenliang committed
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
            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
611 612
            [_pick reloadAllComponents];

xwenliang's avatar
xwenliang committed
613 614 615 616 617 618
            [_pick selectRow:i  inComponent:2 animated:NO];
            break;
        }
    }
}
//两行时候的选择哪个的逻辑
xwenliang's avatar
xwenliang committed
619
-(void)selectValueTwo
xwenliang's avatar
xwenliang committed
620 621 622 623 624 625 626
{
    
    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
627
            
xwenliang's avatar
xwenliang committed
628
            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
629
            [_pick selectRow:i  inComponent:0 animated:NO];
xwenliang's avatar
xwenliang committed
630
            _num=i;
xwenliang's avatar
xwenliang committed
631 632 633
            break;
        }
    }
xwenliang's avatar
xwenliang committed
634 635 636 637 638 639
    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
640
    }
xwenliang's avatar
xwenliang committed
641
    
xwenliang's avatar
xwenliang committed
642 643
    NSString *selectTwoStr;
    if (self.selectValueArry.count>1) {
xwenliang's avatar
xwenliang committed
644
        
xwenliang's avatar
xwenliang committed
645 646 647 648 649 650
        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
651
        
xwenliang's avatar
xwenliang committed
652 653
        if ([selectTwoStr isEqualToString:str]) {
            
xwenliang's avatar
xwenliang committed
654
            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
            [_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
674
                [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
                [_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
697
                            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
                            [_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
716
                            [_pick reloadAllComponents];
xwenliang's avatar
xwenliang committed
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 757 758 759 760 761 762 763
                            [_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
764
            //无关联的,直接给几个选项就行
xwenliang's avatar
xwenliang committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
            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