Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for display in UIPopover #62

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/KalGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#import <UIKit/UIKit.h>
#define NOTIFICATION_SELECTED_DATE @"notificationSelectedDate"

@class KalTileView, KalMonthView, KalLogic, KalDate;
@protocol KalViewDelegate;
Expand Down
4 changes: 2 additions & 2 deletions src/KalGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/KalView.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
@property (nonatomic, assign) id<KalViewDelegate> delegate;
@property (nonatomic, readonly) UITableView *tableView;
@property (nonatomic, readonly) KalDate *selectedDate;
@property (nonatomic, readonly) KalGridView *gridView;

- (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)delegate logic:(KalLogic *)logic;
- (BOOL)isSliding;
Expand Down
2 changes: 1 addition & 1 deletion src/KalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (void)setHeaderTitleText:(NSString *)text;

@implementation KalView

@synthesize delegate, tableView;
@synthesize delegate, tableView, gridView;

- (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)theDelegate logic:(KalLogic *)theLogic
{
Expand Down
3 changes: 2 additions & 1 deletion src/KalViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
KalLogic *logic;
UITableView *tableView;
id <UITableViewDelegate> delegate;
id <KalViewDelegate,UITableViewDelegate> delegate;
id <KalDataSource> 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.
Expand All @@ -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<KalViewDelegate,UITableViewDelegate>)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.

Expand Down
19 changes: 16 additions & 3 deletions src/KalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ @implementation KalViewController

@synthesize dataSource, delegate, initialDate, selectedDate;

- (id)initWithSelectedDate:(NSDate *)date
- (id)initWithSelectedDate:(NSDate *)date andDelegate:(id<KalViewDelegate,UITableViewDelegate>)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]];
Expand All @@ -67,7 +73,7 @@ - (void)setDataSource:(id<KalDataSource>)aDataSource
}
}

- (void)setDelegate:(id<UITableViewDelegate>)aDelegate
- (void)setDelegate:(id<KalViewDelegate,UITableViewDelegate>)aDelegate
{
if (delegate != aDelegate) {
delegate = aDelegate;
Expand Down Expand Up @@ -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<KalViewDelegate>)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];
Expand Down