I have UIDatePicker inside a UIScrollViewer and I update my UITableView (reload) whenever I get a change from the date. But strangely, if I scroll datepicker very quickly it crashes and gives me the following errors?What could it be any idea? Here is the code where I get dateValue and set it to a instance variable (retained) startDate.
[CFString isEqualToString:]: message sent to deallocated instance
- (IBAction) getDateValue:(id) sender {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MMM d, yyyy h:mm a"];
if(field == 2) {
startDate = [NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]];
[tableView reloadData];
}
else if(field == 3) {
endDate = [NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]];
[tableView reloadData];
}
else {
}
[df release];
}
That is not a retained instance variable; it’s autoreleased. This means it will be reallocated by the next time the run loop spins, and is the source of your crash.
I would recommend setting the
startDateandendDatevariables via @property setters instead.