diff --git a/src/KalGridView.h b/src/KalGridView.h index 2253285..3de49d8 100644 --- a/src/KalGridView.h +++ b/src/KalGridView.h @@ -4,6 +4,7 @@ */ #import +#define NOTIFICATION_SELECTED_DATE @"notificationSelectedDate" @class KalTileView, KalMonthView, KalLogic, KalDate; @protocol KalViewDelegate; diff --git a/src/KalGridView.m b/src/KalGridView.m index 798d73e..c7d300d 100644 --- a/src/KalGridView.m +++ b/src/KalGridView.m @@ -95,7 +95,7 @@ - (void)setSelectedTile:(KalTileView *)tile selectedTile = [tile retain]; tile.selected = YES; [delegate didSelectDate:tile.date]; - } + } else [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_SELECTED_DATE object:[tile.date NSDate]]; } - (void)receivedTouches:(NSSet *)touches withEvent:event @@ -142,7 +142,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event } else { [delegate showPreviousMonth]; } - self.selectedTile = [frontMonthView tileForDate:tile.date]; + //self.selectedTile = [frontMonthView tileForDate:tile.date]; } else { self.selectedTile = tile; } diff --git a/src/KalView.h b/src/KalView.h index fe9db0b..75b0ea4 100644 --- a/src/KalView.h +++ b/src/KalView.h @@ -50,6 +50,7 @@ @property (nonatomic, assign) id delegate; @property (nonatomic, readonly) UITableView *tableView; @property (nonatomic, readonly) KalDate *selectedDate; +@property (nonatomic, readonly) KalGridView *gridView; - (id)initWithFrame:(CGRect)frame delegate:(id)delegate logic:(KalLogic *)logic; - (BOOL)isSliding; diff --git a/src/KalView.m b/src/KalView.m index def1dcb..d7a8d9b 100644 --- a/src/KalView.m +++ b/src/KalView.m @@ -19,7 +19,7 @@ - (void)setHeaderTitleText:(NSString *)text; @implementation KalView -@synthesize delegate, tableView; +@synthesize delegate, tableView, gridView; - (id)initWithFrame:(CGRect)frame delegate:(id)theDelegate logic:(KalLogic *)theLogic { diff --git a/src/KalViewController.h b/src/KalViewController.h index ba9ddb9..4104862 100644 --- a/src/KalViewController.h +++ b/src/KalViewController.h @@ -24,7 +24,7 @@ { KalLogic *logic; UITableView *tableView; - id delegate; + id delegate; id dataSource; 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. 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. @@ -35,6 +35,7 @@ @property (nonatomic, retain, readonly) NSDate *selectedDate; - (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. +- (id)initWithSelectedDate:(NSDate *)date andDelegate:(id)aDelegate; - (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. - (void)showAndSelectDate:(NSDate *)date; // Updates the state of the calendar to display the specified date's month and selects the tile for that date. diff --git a/src/KalViewController.m b/src/KalViewController.m index 62245b8..00b68ea 100644 --- a/src/KalViewController.m +++ b/src/KalViewController.m @@ -40,18 +40,24 @@ @implementation KalViewController @synthesize dataSource, delegate, initialDate, selectedDate; -- (id)initWithSelectedDate:(NSDate *)date +- (id)initWithSelectedDate:(NSDate *)date andDelegate:(id)aDelegate { if ((self = [super init])) { logic = [[KalLogic alloc] initForDate:date]; self.initialDate = date; self.selectedDate = date; + self.delegate = aDelegate; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(significantTimeChangeOccurred) name:UIApplicationSignificantTimeChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:KalDataSourceChangedNotification object:nil]; } return self; } +- (id)initWithSelectedDate:(NSDate *)date +{ + return [self initWithSelectedDate:[NSDate date]]; +} + - (id)init { return [self initWithSelectedDate:[NSDate date]]; @@ -67,7 +73,7 @@ - (void)setDataSource:(id)aDataSource } } -- (void)setDelegate:(id)aDelegate +- (void)setDelegate:(id)aDelegate { if (delegate != aDelegate) { delegate = aDelegate; @@ -183,11 +189,18 @@ - (void)loadView { if (!self.title) self.title = @"Calendar"; - KalView *kalView = [[[KalView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] delegate:self logic:logic] autorelease]; + + CGRect popoverRect = CGRectMake(0, 0, self.contentSizeForViewInPopover.width, self.contentSizeForViewInPopover.height); + CGRect windowsRect = [[UIScreen mainScreen] applicationFrame]; + + CGRect rect = CGRectMake(0, 0, MIN(popoverRect.size.width, windowsRect.size.width), MIN(popoverRect.size.height, windowsRect.size.height)); + + KalView *kalView = [[[KalView alloc] initWithFrame:rect delegate:delegate != nil ? (id)delegate:self logic:logic] autorelease]; self.view = kalView; tableView = kalView.tableView; tableView.dataSource = dataSource; tableView.delegate = delegate; + [tableView removeFromSuperview]; [tableView retain]; [kalView selectDate:[KalDate dateFromNSDate:self.initialDate]]; [self reloadData];