You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This closes issue #23 on GitHub. The issue was related to how we re-construct the view hierarchy after a low memory warning from the system. If the user had changed to a month different than the initial month when KalViewController was created, it would fail to find the appropriate KalTileView for the value that it had stored as the initially selected date. The solution is to re-cache the initially selected date when a low memory warning occurs.
Original bug report by jgchristian:
Steps to reproduce:
1. Start your Holiday app
2. Slide to the next month (i.e. not the current month)
3. Select an event and view the holiday details
4. When on the details screen, quit to the springboard by single clicking the home button (not double clicking to background). We need to force the device to want to reload the grid when we return - so you may need to do some memory intensive stuff - but not generally the case for me.
5. Relaunch the Holiday app. This returns you to the details screen
6. Now press back to return to the grid. Crash log below
From the looks of the code this is happening because the 'logic' object is still on the next month (correct), but when loadView is triggered by the OS trying to re-instantiate the view it defaults to setting the current date on the grid - which was in the previous month so assertion fails as cell is nil.
Thought about maintaining last user-selected date but started to get fiddly.
2011-02-02 08:20:24.961 Holiday[3471:307] Received memory warning. Level=2
2011-02-02 08:20:28.382 Holiday[3471:307] Assertion failure in -[KalMonthView tileForDate:], /Users/j.christian/dev/Kal/src/KalMonthView.m:84
2011-02-02 08:20:28.510 Holiday[3471:307] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to find corresponding tile for date 2/2/2011'
Copy file name to clipboardexpand all lines: src/KalViewController.h
+3-2
Original file line number
Diff line number
Diff line change
@@ -26,15 +26,16 @@
26
26
UITableView *tableView;
27
27
id <UITableViewDelegate> delegate;
28
28
id <KalDataSource> dataSource;
29
-
NSDate *initialSelectedDate;
29
+
NSDate *initialDate; // The date that the calendar was initialized with *or* the currently selected date when the view hierarchy was torn down in order to satisfy a low memory warning.
30
+
NSDate *selectedDate; // I cache the selected date because when we respond to a memory warning, we cannot rely on the view hierarchy still being alive, and thus we cannot always derive the selected date from KalView's selectedDate property.
- (id)initWithSelectedDate:(NSDate *)selectedDate; // designated initializer. When the calendar is first displayed to the user, the month that contains 'selectedDate' will be shown and the corresponding tile for 'selectedDate' will be automatically selected.
36
38
- (void)reloadData; // If you change the KalDataSource after the KalViewController has already been displayed to the user, you must call this method in order for the view to reflect the new data.
37
39
- (void)showAndSelectDate:(NSDate *)date; // Updates the state of the calendar to display the specified date's month and selects the tile for that date.
38
-
- (NSDate *)selectedDate; // The currently selected date. You should only use the actual date components from this NSDate object. The hours/minutes/seconds/timezones are undefined.
0 commit comments