У меня есть одна дата сборщика.Когда я изменяю дату и показываю.Работает нормально.Но если я не изменю дату и не нажму кнопку ОК.Получение сбоя. Вот мой код:
NSDate *reportingDate;
NSDateFormatter *pickerDateFormatter;
- (void)viewDidLoad {
[self updatePickerUI];
}
- (void)updatePickerUI {
_pickerView.hidden = true;
self.picker.monthPickerDelegate = self;
self.picker.maximumYear = 2115;
self.picker.minimumYear = 1900;
self.picker.yearFirst = YES;
NSString *mon = [userDefault objectForKey:@"monthText"];
NSString *yr = [userDefault objectForKey:@"YearText"];
NSLog(@"%@%@", mon,yr);
self.dateLabel.text = [NSString stringWithFormat: @"%@,%@", mon, yr];
}
- (NSString*)formatDate:(NSDate *)date
{
if (pickerDateFormatter == nil) {
pickerDateFormatter = [[NSDateFormatter alloc] init];
}
pickerDateFormatter.dateFormat = @"MMM, yyyy";
return [pickerDateFormatter stringFromDate:date];
}
- (void)monthPickerDidChangeDate:(SRMonthPicker *)monthPicker
{
reportingDate = monthPicker.date;
NSString *selectedDate = [self formatDate:reportingDate];
[self updateDateLabel:selectedDate];
}
Окей действие кнопки:
- (IBAction)pickerAction:(id)sender {
if ([sender isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)sender;
if ([button.titleLabel.text isEqualToString:@"Cancel"]) {
return;
}
}
NSDate *pickerDate = reportingDate;
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:pickerDate];
NSInteger reportingMonth = [components month];
NSInteger reportingYear = [components year];
NSString *Month = [NSString stringWithFormat:@"%ld", (long)reportingMonth];
NSString *Yrs = [NSString stringWithFormat:@"%ld", (long)reportingYear];
NSString *temp = @"0";
if (Month.length == 1) {
SelMonth = [temp stringByAppendingString:Month];
}else {
SelMonth = Month;
}
[str setObject:SelMonth forKey:@"month"];
[str setObject:Yrs forKey:@"year"];
NSString *Mont = [self MonthNameString:[SelMonth integerValue]];
}
Сбой здесь этой строки:
NSInteger reportsMonth = [компонентымесяц];NSInteger ReportYear = [год компонентов];
Спасибо