To present a view from your UIViewController, implement two interfaces: the MAFCalendarViewDataSource interface requests appointments from your application and the MAFCalendarViewDelegate lists event callback methods that are called by the MAF Calendar control to handle specific events.
#import <UIKit/UIKit.h>
#import "MAFCalendarView.h"
@interface RootViewController : UIViewController<MAFCalendarViewDataSource,MAFCalendarViewDelegate>
{
}
-(BOOL) isDate:(NSDate*)date withinStart:(NSDate*)startDate andEnd:(NSDate*)endDate
{
return [date isWithinStart:startDate andEnd:(NSDate*)endDate];
}
-(NSArray *)calendarView:(MAFCalendarView *)sender getAppointmentsFromStart:(NSDate *)start toEnd:(NSDate *)end
{
// please note this data source is for demo purposes only
NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease];
for(MAFAppointment* app in arr)
{
if([self isDate:app.startDate withinStart:start andEnd:end])
[ret addObject:app];
}
return ret;
}
-(void)createData
{
arr = [[NSMutableArray alloc] init];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Berlin"]];
[dateFormat setDateFormat:@"dd-MM-yyyy HH:mm"];
MAFCalendar* cal = [[[MAFCalendar alloc] init] autorelease];
cal.name = @"First Calendar";
cal.color = [UIColor colorWithRed:177/255.0f green:211/255.0f blue:74/255.0f alpha:1.0];
cal.bordercolor = [UIColor colorWithRed:0/255.0f green:138/255.0f blue:59/255.0f alpha:1.0];
MAFCalendar* cal2 = [[[MAFCalendar alloc] init] autorelease];
cal2.name = @"Second Calendar";
cal2.color = [UIColor colorWithRed:0/255.0f green:161/255.0f blue:228/255.0f alpha:1.0];
cal2.bordercolor = [UIColor colorWithRed:0/255.0f green:116/255.0f blue:187/255.0f alpha:1.0];
MAFCalendar* cal3 = [[[MAFCalendar alloc] init] autorelease];
cal3.name = @"Third Calendar";
cal3.color = [UIColor colorWithRed:246/255.0f green:139/255.0f blue:31/255.0f alpha:1.0];
cal3.bordercolor = [UIColor colorWithRed:203/255.0f green:77/255.0f blue:44/255.0f alpha:1.0];
NSDate* today = [NSDate date];
today = [NSDate toDayBoundaryFloor:today withTimeZone:[NSTimeZone localTimeZone]];
NSTimeInterval d = 60*60*24;
MAFAppointment* app = [[[MAFAppointment alloc] init] autorelease];
app.startDate = [NSDate dateWithTimeInterval:10*60*60.0+d sinceDate:today];
app.endDate = [NSDate dateWithTimeInterval:11*60*60.0+d sinceDate:today];
app.title = @"Meeting 2204";
app.location = @"Walldorf";
app.notes = @"notes";
app.calendar = cal;
[arr addObject:app];
app = [[[MAFAppointment alloc] init] autorelease];
app.startDate = [NSDate dateWithTimeInterval:12*60*60.0+d sinceDate:today];
app.endDate = [NSDate dateWithTimeInterval:13*60*60.0+d sinceDate:today];
app.title = @"Lunch";
app.location = @"Walldorf";
app.notes = @"notes";
app.calendar = cal2;
[arr addObject:app];
app = [[[MAFAppointment alloc] init] autorelease];
app.startDate = [NSDate dateWithTimeInterval:11*60*60.0+d sinceDate:today];
app.endDate = [NSDate dateWithTimeInterval:14*60*60.0+d sinceDate:today];
app.title = @"Meeting 2";
app.location = @"Walldorf";
app.notes = @"notes";
app.calendar = cal3;
[arr addObject:app];
}
You can now initialize and present your MAFAppointments on any of the
MAFCalendarViews.