2013-02-07 2 views
0

달력을 구현하려면 Kal https://github.com/klazuka/Kal을 사용하고 있습니다. 나는 스토리 보드를 사용하고 있으므로 컨테이너 뷰 컨트롤러에 자식으로 KalViewController를 추가합니다. 칼 데이터 원본 대리자

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]; 

나는 데이터 소스 대표와 같은 외부 객체를 사용하지만, 웹 서비스에 의해 내 백엔드에서 데이터를 가져 오는 후, 내가 가져온 데이터와 달력을로드 할 대의원을 호출하는 방법을 모르는 :

@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:&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<KalDataSourceCallbacks>)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; 

    } 

답변

3

우선 나는 당신이 그것을 사용 후 KalViewController를 ALLOC 이상한 발견, 나는 그 반대 순서로 그것을 할 것입니다 : 다음

kal = [[KalViewController alloc] init]; 
kal.delegate = self; 
kal.dataSource = dataSource; 

그리고 왜 당신은 그냥 전화하지?

[kal reloadData];