// // ShowGenderAlertView.m // smartRhino // // Created by armin on 2019/11/1. // Copyright © 2019 tederen. All rights reserved. // #import "ShowGenderAlertView.h" @interface ShowGenderAlertView () @property (copy, nonatomic) void(^confirmBlock)(NSString *gender); @property (copy, nonatomic) void(^cancelBlock)(void); @property (strong,nonatomic) IBOutlet UIPickerView *pickView; @property (strong,nonatomic) NSString *selectGender; @property (strong,nonatomic) IBOutlet NSLayoutConstraint *bottomH; @end @implementation ShowGenderAlertView static UINib *ViewNib = nil; + (instancetype)selectView{ if (ViewNib == nil) { ViewNib = [UINib nibWithNibName:@"ShowGenderAlertView" bundle:nil]; } ShowGenderAlertView *alert = [[ViewNib instantiateWithOwner:nil options:nil] lastObject]; return alert; } /** * 弹出选择性别 */ +(instancetype)initShowGenderAlertViewWithGender:(NSString *)genderStr confirm:(void (^)(NSString * _Nonnull))confirmBlock cancle:(void (^)(void))cancleBlock{ ShowGenderAlertView *alert = [self selectView]; [alert setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; alert.bottomH.constant = 284 + kiphoneXBootomHeight; //初始默认值 alert.selectGender = genderStr; alert.pickView.delegate = alert; alert.pickView.dataSource = alert; if([genderStr isEqualToString:@"男"]){ [alert.pickView selectRow:0 inComponent:0 animated:NO]; }else if([genderStr isEqualToString:@"女"]){ [alert.pickView selectRow:1 inComponent:0 animated:NO]; } [alert setStatusBarStyle:UIStatusBarStyleDefault]; [alert setGesture:YES]; [alert setConfirmBlock:confirmBlock]; [alert setCancelBlock:cancleBlock]; return alert; } -(IBAction)userDidBackClickAction:(id)sender{ [self dismissWithAnimation:kAlertAnimationBottom]; if(self.cancelBlock){ self.cancelBlock(); } } -(IBAction)userDidSureClickAction:(id)sender{ [self dismissWithAnimation:kAlertAnimationBottom]; if(self.confirmBlock){ self.confirmBlock(self.selectGender); } } #pragma mark - dataSouce //有几行 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } //行中有几列 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return 2; } //列显示的数据 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger) row forComponent:(NSInteger)component { if(row == 0){ return @"男"; } return @"女"; } #pragma mark - delegate // 选中某一组的某一行 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { switch (row) { case 0: self.selectGender = @"男"; break; case 1: self.selectGender = @"女"; break; default: break; } } @end