Trouble with datasource not being called from viewWillAppear
- by user278859
A little background. I have taken GCCalendar which only works in portrait orientation and extended it to work in landscape similar to how the iPhone's Calendar app works. I did this by duplicating the main view class and modifying it to work in landscape. So when the phone is in portrait orientation the CGCalendar is instantiated from the apps main view controller using the original portrait view class and when in landscape orientation using the new modified landscape view class. Most of the other classes in GCCalendar are shared without modification. A few had to be duplicated as well.
I got it all working great except for an issue with the datasource. The datasource is called when the calendar is first loaded and each time the user changes the dates being viewed. Problem is I can't get the datasource call to work on the first call.
I am stumped as it works fine in portrait orientation and I cannot find any difference between the 2 versions.
Following is some of the code that shows how it gets to the datasource call the first time. Subsequent calls removes all the calendar subviews and instantiates them again with the new dates. The duplicated landscape class names end in LS. Otherwise as you can see they are identical.
Does anyone has any idea of where else I might look to resolve this issue?
Thanks,
John
--------------------------------
//App main view controller
- (void)showLandscapeCalendar {
GCCalendarLandscapeView *calendar = [[[GCCalendarLandscapeView alloc] init] autorelease];
calendar.dataSource = self;
calendar.delegate = self;
navigationController = [[UINavigationController alloc] initWithRootViewController:calendar];
[self presentModalViewController:navigationController animated:YES];
}
- (void)showPortraitCalendar {
GCCalendarPortraitView *calendar = [[[GCCalendarPortraitView alloc] init] autorelease];
calendar.dataSource = self;
calendar.delegate = self;
navigationController = [[UINavigationController alloc] initWithRootViewController:calendar];
[self presentModalViewController:navigationController animated:YES];
}
- (NSArray *)calendarEventsForDate:(NSDate *)date{
//build and return the events array
//this is the protocol datasource method
//It is supposed to run every time the date changes in the calendar
}
-------------------------------
// GCCalendarLandscapeView...
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (viewDirty) {
[self reloadDayAnimated:NO context:NULL];
viewDirty = NO;
}
viewVisible = YES;
}
- (void)reloadDayAnimated:(BOOL)animated context:(void *)context {
GCCalendarDayViewLS *nextDayView = [[GCCalendarDayViewLS alloc] initWithCalendarView:self];
}
-------------------------------
//GCCalendarDayViewLS
- (id)initWithCalendarView:(GCCalendarView *)view {
if (self = [super init]) {
dataSource = view.dataSource;
}
return self;
}
- (void)reloadData {
//** first time through the dataSource method does not run
events = [dataSource calendarEventsForDate:date];
}
-------------------------------
// GCCalendarPortraitView...
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (viewDirty) {
[self reloadDayAnimated:NO context:NULL];
viewDirty = NO;
}
viewVisible = YES;
}
- (void)reloadDayAnimated:(BOOL)animated context:(void *)context {
GCCalendarDayView *nextDayView = [[GCCalendarDayView alloc] initWithCalendarView:self];
}
-------------------------------
//GCCalendarDayView
- (id)initWithCalendarView:(GCCalendarView *)view {
if (self = [super init]) {
dataSource = view.dataSource;
}
return self;
}
- (void)reloadData {
**//this one works every time
events = [dataSource calendarEventsForDate:date];
}