Note that there are some explanatory texts on larger screens.

plurals
  1. POKal datasource delegates
    primarykey
    data
    text
    <p>I'm usin Kal <a href="https://github.com/klazuka/Kal" rel="nofollow">https://github.com/klazuka/Kal</a> to implement a calendar. I'm using storyboard, so I add KalViewController as a child to the container view controller. </p> <pre><code>kal.delegate = self; kal.dataSource = dataSource; dataSource = [[CalendarDataSourceDelegate alloc] init]; kal = [[KalViewController alloc] init]; [self addChildViewController:kal]; [kal didMoveToParentViewController:self]; [self.calendarioView addSubview:kal.view]; [clickEvent insertPrintAdd:zona_competicion]; </code></pre> <p>I use an external object as datasource delegate, but after fetching data from my backend by webservice, I don't know how to call delegates to load calendar with fetched data:</p> <pre><code>@implementation CalendarDataSourceDelegate - (id)init { if ((self = [super init])) { items = [[NSMutableArray alloc] init]; matches = [[NSMutableArray alloc] init]; buffer = [[NSMutableData alloc] init]; } [self fetchHolidays]; return self; } - (eventMatch *)eventAtIndexPath:(NSIndexPath *)indexPath { return [items objectAtIndex:indexPath.row]; } #pragma mark UITableViewDataSource protocol conformance - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"MyCell"; eventNoAddedCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[eventNoAddedCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:identifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; } eventMatch *event = [self eventAtIndexPath:indexPath]; cell.escudoLocal.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",event.equipoLocal ]]; cell.escudoVis.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",event.equipoVisitante ]]; cell.equipoLocal.text = event.equipoLocal; cell.equipoVisitante.text = event.equipoVisitante; cell.competicion.text = event.competicion; cell.jornada.text = event.jornada; cell.hora.text = event.hora; cell.canalesTV.text = event.canalesTV; [self fetchHolidays]; return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [items count]; } #pragma mark Fetch from the internet - (void)fetchHolidays { NSString *urlStr = [NSString stringWithFormat:@"http://backend.exular.net/contenido/webservices/xlr_ws_calendario.php?idp=105"]; dataReady = NO; [matches removeAllObjects]; conn = [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] delegate:self]; [conn start]; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [buffer setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [buffer appendData:data]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSError *error=nil; NSDictionary *tempDic = [NSJSONSerialization JSONObjectWithData:buffer options:kNilOptions error:&amp;error]; NSArray *array = [tempDic valueForKey:@"nodes"]; NSDateFormatter *fmt = [[NSDateFormatter alloc] init] ; [fmt setDateFormat:@"dd/MM/yyyy"]; for (NSDictionary *jornada in array) { NSDate *d = [fmt dateFromString:[jornada objectForKey:@"fecha"]]; [matches addObject:[eventMatch equipoVisitante:[jornada valueForKey:@"id_visitante"] equipoLocal:[jornada valueForKey:@"id_local"] resultadoVisitante:[jornada valueForKey:@"res_visitante"] resultadoLocal:[jornada valueForKey:@"res_local"] canalesTV:[jornada valueForKey:@"cadenas"] date:d time:[jornada valueForKey:@"hora"] jornada:[jornada valueForKey:@"jornada"] competicion:[jornada valueForKey:@"competicion"]]]; } dataReady = YES; [callback loadedDataSource:self]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"HolidaysCalendarDataSource connection failure: %@", error); } #pragma mark KalDataSource protocol conformance - (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id&lt;KalDataSourceCallbacks&gt;)delegate { /* * In this example, I load the entire dataset in one HTTP request, so the date range that is * being presented is irrelevant. So all I need to do is make sure that the data is loaded * the first time and that I always issue the callback to complete the asynchronous request * (even in the trivial case where we are responding synchronously). */ if (dataReady) { [callback loadedDataSource:self]; return; } callback = delegate; [self fetchHolidays]; } - (NSArray *)markedDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate { if (!dataReady) return [NSArray array]; return [[self matchesFrom:fromDate to:toDate] valueForKeyPath:@"date"]; } - (void)loadItemsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate { if (!dataReady) return; [items addObjectsFromArray:[self matchesFrom:fromDate to:toDate]]; } - (void)removeAllItems { [items removeAllObjects]; } #pragma mark - - (NSArray *)matchesFrom:(NSDate *)fromDate to:(NSDate *)toDate { NSMutableArray *matchesUpdate = [NSMutableArray array]; for (eventMatch *match in matches) if (IsDateBetweenInclusive(match.date, fromDate, toDate)) [matchesUpdate addObject:match]; return matches; } - (void)dealloc { matches=nil; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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