I figured this one out.
Here is the code which allowed the controlled to be reused.
- (void)switchToViewMode:(NSInteger)viewMode {
UICollectionViewLayout *layout;
CalendarView *view;
CGRect oldFrame;
switch (viewMode) {
case 0:
case 1:
layout = [[DayCollectionViewLayout alloc] initWithCoder:nil];
oldFrame = self.collectionView.frame;
view = [[CalendarView alloc] initWithFrame:oldFrame collectionViewLayout:layout];
self.dataSource = [[DayDataSource alloc] initWithScheduleNumber:0]; // TODO set correct date
view.dataSource = self.dataSource;
view.backgroundColor = [UIColor whiteColor];
self.collectionView = view;
break;
case 2:
layout = [[WeekCollectionViewLayout alloc] initWithCoder:nil];
oldFrame = self.collectionView.frame;
view = [[CalendarView alloc] initWithFrame:oldFrame collectionViewLayout:layout];
self.dataSource = [[WeekDataSource alloc] init];
view.dataSource = self.dataSource;
view.backgroundColor = [UIColor whiteColor];
self.collectionView = view;
break;
default:
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Unknown view mode selected." userInfo:nil];
break;
}
}