#pragma mark — 选择生日
- (void)editBrithday {
UIAlertView * _brithdayAlert = [UIAlertView new];
_brithdayAlert.title = @"编辑生日";
[_brithdayAlert addButtonWithTitle: @"取消"];
[_brithdayAlert addButtonWithTitle: @"确认"];
// UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
[self initDatePicker];
_datePicker.datePickerMode = UIDatePickerModeDate;//选择年月日模式
[_brithdayAlert setValue:_datePicker forKey:@"accessoryView"];
[_brithdayAlert show];
}
// 初始化日期选择器
- (void)initDatePicker
{
_datePicker = [[UIDatePicker alloc]init];
_datePicker.frame = CGRectMake(0, 40, self.view.frame.size.width, self.view.frame.size.height*175/340);
[_datePicker addTarget:self action:@selector(timeChanged:) forControlEvents:UIControlEventValueChanged];
NSArray *strArray = [_arrTitle[2] componentsSeparatedByString:@":"];
NSString * brithdayStr = strArray[1];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
_currentBrithdayDate = [dateFormatter dateFromString:brithdayStr];
_datePicker.date = _currentBrithdayDate;
_datePicker.maximumDate = [NSDate date];
}
// 停止滚动的时候的方法
- (void)timeChanged:(UIDatePicker *)datePicker
{
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"yyyy-MM-dd";
NSString *text = [formatter stringFromDate:datePicker.date];
_birthdayStr = text;
//刷生日进表
[_arrTitle replaceObjectAtIndex:2 withObject:[NSString stringWithFormat:@"生日:%@", _birthdayStr]];
//根据获得的年与日拿到我们需要的月日数据进行星座转换
NSArray *strArray = [_birthdayStr componentsSeparatedByString:@"-"];
NSString * month = strArray[1];
NSString * day = strArray[2];
NSString * constellation = [self calculateConstellationWithMonth: [month integerValue] day:[day integerValue]];
[_arrTitle replaceObjectAtIndex:3 withObject:[NSString stringWithFormat:@"星座:%@", constellation]];
[_tableView reloadData];
}