Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>Define a class which implements the <code>KalDataSource</code> protocol. See below example for class implementing <code>KalDataSource</code> protocol.</p> <pre><code>//header file #import Kal.h" @interface MyClass : NSObject &lt;KalDataSource&gt; @property (nonatomic, weak) id&lt;KalDataSourceCallbacks&gt; kalCallbackDelegate; @property (nonatomic, strong) NSArray *events; @end ---------------------- //implementation file - (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id&lt;KalDataSourceCallbacks&gt;)callbackDelegate { //If you already have the events between fromDate and toDate then just call [callbackDelegate loadedDataSource:self]; //Else store the callback variable in a property and do an asyncrhonous //call to load the events. self.kalCallbackDelegate = callbackDelegate; //When the Asynchronous call is done, call [self.kalCallbackDelgate loadedDataSource:self]; } - (void)removeAllItems { self.eventsForDay = nil; } - (NSArray *)markedDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate { //self.events may have multiple events with the same date. This pulls only the unique dates. //Also assumes that the object has an eventDate property for the beginning of the day NSMutableSet *uniqueDatesSet = [NSMutableSet setWithArray:[self.events valueForKeyPath:@"@distinctUnionOfObjects.eventDate"]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self &gt;= %@ &amp;&amp; self &lt;= %@", fromDate, toDate]; NSArray *uniqueDates = [[uniqueDatesSet allObjects] filteredArrayUsingPredicate:predicate]; return uniqueDates; } - (void)loadItemsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate { //filter for the events that occur between fromDate and toDate NSPredicate *predicate = [NSPredicate predicateWithFormat:@"eventDate &gt;= %@ &amp;&amp; eventDate &lt;= %@", fromDate, toDate]; NSArray *filteredArray = [self.events filteredArrayUsingPredicate:predicate]; self.eventsForDay = [filteredArray sortedArrayUsingSelector:@selector(compareByEventTime:)]; } </code></pre></li> <li><p>To render the UITableViewCells, implement <code>tableView:cellForRowAtIndexPath:</code> in your <code>KalDataSource</code> class just like you would for a <code>UITableView</code>.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { Event *event = [self.events objectAtIndex:indexPath.row]; static NSString *identifier = @"MyCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } cell.textLabel.text = event.title; return cell; } </code></pre></li> <li><p>If you want to know when a <code>UITableViewCell</code> is selected, define a class implementing the <code>UITableViewDelegate</code> protocol and set <code>_departDatePicker.delegate</code> equal to that class. Then you can implement the regular <code>UITableViewDelegate</code> methods in that class.</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Event *event = [self.events objectAtIndex:indexPath.row]; MyViewController *viewController = [[UIStoryboard storyboardWithName:@"iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"eventInfo"]; viewController.event = event; [self.navigationController pushViewController:viewController animated:YES]; } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload