Data Source Helper
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides a conceptual overview of data source helper in the IGCalendarView™ and demonstrates how to configure it using a code example.

In this topic


Introduction

Data source helper summary

Use the data source helper to provide a data source for displaying EKEventStore appointments stored on your iOS device. Additionally, the data source helper knows how to make appointment requests for you. The IGCalendarView provides a data source helper. When you create a reference to the EKEventStore, you will need to retain this reference as the IGCalendarEKDataSourceHelper only holds a weak reference. The data source helper pulls the appointment color from the EKCalendar as well as the appointment information to display. When a user taps one of the displayed appointments call an optional IGCalendarViewDelegate method, calendarView:appointmentTapped:fromDataSource:withBounds:forDay:, you can retrieve the EKEvent reference by using the following code.

In Objective-C:

-(void)calendarView:(IGCalendarView *)calView appointmentTapped:(IGCalendarAppointment *)appt fromDataSource:(id<IGCalendarAppointmentDataSource>)dataSource withBounds:(CGRect)rect forDay:(NSDate *)date
{
     IGCalendarEKDataSourceHelper *ds = (IGCalendarEKDataSourceHelper *)dataSource;       
     EKEvent *ekEvent = [ds resolveEventFromAppointment:appt];
}

In C#:

public override void AppointmentTapped (IGCalendarView calView, IGCalendarAppointment appt, IGCalendarAppointmentDataSource dataSource, RectangleF rect, NSDate date)
{
      IGCalendarEKDataSourceHelper ds = dataSource as IGCalendarEKDataSourceHelper;
      EKEvent ekEvent = ds.ResolveEventFromAppointment(appt);
}

IGCalendarView Data Source Helper – Code Example

Description

The code below creates an instance of the IGCalendarView and populates the displayed appointments by using all the calendars found through EKEventStore.

Prerequisites

This code example requires the inclusion of the IG framework, detail about how to add this framework can be found in the Adding the IG Framework File topic.

Code

In Objective-C:

@interface igViewController ()
{
    EKEventStore *_store;
    NSMutableArray *_dataSources;
}
@end
@implementation igViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _dataSources = [[NSMutableArray alloc] init];
    _store = [[EKEventStore alloc] init];
    [_store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
    {
        if(granted)
        {
            NSArray *cals = [_store calendarsForEntityType:EKEntityTypeEvent];
            int index = 0;
            for(EKCalendar* cal in cals)
            {
                IGCalendarEKDataSourceHelper *ds = [[IGCalendarEKDataSourceHelper alloc] initWithCalendar:cal forStore:_store];
                [_dataSources addObject:ds];
                index++;
            }
        }
    }];
    IGCalendarView *calendar = [[IGCalendarView alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 10)];
    calendar.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    calendar.appointmentDataSources = _dataSources;
    [self.view addSubview:calendar];
}
@end

In C#:

public partial class CalendarDataSourceHelper_CSViewController : UIViewController
{
      EKEventStore _store;
      List<NSObject> _dataSources;
      public CalendarDataSourceHelper_CSViewController ()
      {
      }
      public override void ViewDidLoad ()
      {
            base.ViewDidLoad ();
            this.View.BackgroundColor = UIColor.White;
            _dataSources = new List<NSObject>();
            _store = new EKEventStore();
            _store.RequestAccess (EKEntityType.Event, (bool granted, NSError NSError) => {
                  if(granted)
                  {
                        EKCalendar[] cals = _store.GetCalendars(EKEntityType.Event);
                        int index = 0;
                        foreach(EKCalendar cal in cals)
                        {
                              IGCalendarEKDataSourceHelper ds = new IGCalendarEKDataSourceHelper(cal, _store);
                              _dataSources.Add(ds);
                              index++;
                        }
                  }
            });
            IGCalendarView calendar = new IGCalendarView();
            calendar.Frame = this.View.Bounds;
            calendar.Frame.Inflate (-10, -10);
            calendar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth|UIViewAutoresizing.FlexibleHeight;
            calendar.AppointmentDataSources = _dataSources.ToArray();
            this.View.Add (calendar);
      }
}

Related Content

Topics

The following topic provides additional information related to this topic.

Topic

Purpose

This section serves as an introduction to the IGCalendarView key features and functionalities.