0

我有一个日期选择器并随机收到一个崩溃,说它有更多的 100,000 行。这怎么可能?有谁知道为什么会发生此错误,以及将来如何防止它?

- (void)showDatePicker
{   

    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                              delegate:nil
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];


    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSString *startTimeString = [MathFunctions minutesToTimeString:[appointment.start_time integerValue]];
    [dateFormatter setDateFormat:@"yyyyMMdd h:mm a"];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
    NSString *dateTimeString = [NSString stringWithFormat:@"%@ %@", appointment.date, startTimeString];

    datePicker.date = [dateFormatter dateFromString:dateTimeString];
    [actionSheet addSubview:datePicker];

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:closeButton];

    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
    actionSheet.frame = CGRectMake(actionSheet.frame.origin.x, actionSheet.frame.origin.y, actionSheet.frame.size.width, 320);
}

崩溃原因:

Reason: Failed to allocate data stores for 100000 rows in section 0. Consider using fewer rows

崩溃分析日志:

CoreFoundation  __exceptionPreprocess + 162
1    libobjc.A.dylib    objc_exception_throw + 32
2    CoreFoundation +[NSException raise:format:]
3    Foundation -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
4    UIKit  -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1780
5    UIKit  -[UITableViewRowData numberOfRows] + 108
6    UIKit  -[UITableView noteNumberOfRowsChanged] + 118
7    UIKit  -[UITableView reloadData] + 730
8    UIKit  -[UIPickerView layoutSubviews] + 3430
9    UIKit  -[UIDatePickerView layoutSubviews] + 62
10   UIKit  -[UIPickerView _selectRow:inComponent:animated:notify:] + 80
11   UIKit  -[UIDatePickerView _selectRow:inComponent:animated:notify:] + 50
12   UIKit  -[UIDatePickerView _loadDateAnimated:] + 836
13   UIKit  -[UIDatePickerView _updateBitsForDate:forced:andReload:animateIfNeeded:] + 696
14   UIKit  -[UIDatePickerView _setDate:animated:forced:] + 348
15   UIKit  -[UIDatePickerView setDate:animated:] + 30
16   UIKit  -[UIDatePicker setDate:] + 36
4

0 回答 0