Skip to content

Commit

Permalink
Added support for the KalDataSource to notify Kal that the UI needs t…
Browse files Browse the repository at this point in the history
…o be refreshed. Added EKEventStoreChangedNotification handling to NativeCal example app.
  • Loading branch information
klazuka committed Jul 9, 2010
1 parent 843d79b commit 1e51cb1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Examples/NativeCal/Classes/EventKitDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ - (id)init
eventStore = [[EKEventStore alloc] init];
events = [[NSMutableArray alloc] init];
items = [[NSMutableArray alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventStoreChanged:) name:EKEventStoreChangedNotification object:nil];
}
return self;
}

- (void)eventStoreChanged:(NSNotification *)note
{
[[NSNotificationCenter defaultCenter] postNotificationName:KalDataSourceChangedNotification object:nil];
}

- (EKEvent *)eventAtIndexPath:(NSIndexPath *)indexPath
{
return [items objectAtIndex:indexPath.row];
Expand Down Expand Up @@ -100,6 +106,7 @@ - (NSArray *)eventsFrom:(NSDate *)fromDate to:(NSDate *)toDate

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:EKEventStoreChangedNotification object:nil];
[eventStore release];
[items release];
[events release];
Expand Down
5 changes: 3 additions & 2 deletions Examples/NativeCal/NativeCal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
isa = PBXContainerItemProxy;
containerPortal = 533B295311E4A89500B3CC07 /* Kal.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = D2AAC07E0554694100DB518D /* libKal.a */;
remoteGlobalIDString = D2AAC07E0554694100DB518D;
remoteInfo = Kal;
};
533B295D11E4A8BA00B3CC07 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 533B295311E4A89500B3CC07 /* Kal.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = D2AAC07D0554694100DB518D /* Kal */;
remoteGlobalIDString = D2AAC07D0554694100DB518D;
remoteInfo = Kal;
};
/* End PBXContainerItemProxy section */
Expand Down Expand Up @@ -276,6 +276,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ../../src;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-all_load";
PREBINDING = NO;
SDKROOT = iphoneos4.0;
Expand Down
5 changes: 5 additions & 0 deletions src/Kal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@

#import "KalViewController.h"
#import "KalDataSource.h"

// The KalDataSource implementation should post this notification
// whenever its content has changed. Kal uses this notification to
// keep the UI in sync with the data source.
extern NSString *const KalDataSourceChangedNotification;
4 changes: 4 additions & 0 deletions src/KalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void mach_absolute_difference(uint64_t end, uint64_t start, struct timespec *tp)
}
#endif

NSString *const KalDataSourceChangedNotification = @"KalDataSourceChangedNotification";

@interface KalViewController ()
- (KalView*)calendarView;
@end
Expand All @@ -41,6 +43,7 @@ - (id)initWithSelectedDate:(NSDate *)selectedDate
if ((self = [super init])) {
logic = [[KalLogic alloc] initForDate:selectedDate];
initialSelectedDate = [selectedDate retain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:KalDataSourceChangedNotification object:nil];
}
return self;
}
Expand Down Expand Up @@ -188,6 +191,7 @@ - (void)viewDidAppear:(BOOL)animated

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:KalDataSourceChangedNotification object:nil];
[initialSelectedDate release];
[logic release];
[tableView release];
Expand Down

0 comments on commit 1e51cb1

Please sign in to comment.