大屏日历异步加载每天比赛数目并显示在日历里

#import <QuartzCore/QuartzCore.h>  
  #import "CalendarController.h"
 #import "TdCalendarView.h"
 #import "WaitDialog.h"
 #import "JSONParser.h"
 #import "FunUtil.h"
@implementation CalendarController  
@synthesize calendarView;  
@synthesize currentSelectDate;  

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  
    1.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
    2.     if (self) {  
    3.         self.title = @"比赛时间";  
    4.         //self.view.backgroundColor = [UIColor whiteColor];  
    5.         //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back.png"]];   
    6.         calendarView = [[TdCalendarView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];  
    7.         calendarView.backgroundColor = [UIColor whiteColor];  
    8.         //calendarView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back.png"]];   
    9.         [self.view addSubview:calendarView];  
    10.         [calendarView setDayFlag:15 flag:-1];  
    11.         calendarView.calendarViewDelegate = self;  
    12.     }  
    13.     return self;  
    14. }  
    15. - (void) selectDateChanged:(CFGregorianDate) selectDate{  
    16.     currentSelectDate = selectDate;  
    17.     NSLog(@"selectDateChanged catch:%d年%d月%d日",selectDate.year,selectDate.month,selectDate.day);  
    18. }  
    19. - (void) monthChanged:(CFGregorianDate) currentMonth viewLeftTop:(CGPoint)viewLeftTop height:(float)height{  
    20.     NSLog(@"monthChanged catch:%d",currentMonth.month);  
    21.     self.currentSelectDate = currentMonth;
    22.     [NSThread 

detachNewThreadSelector:@selector(fetchdata) toTarget:self withObject:nil];//创建一个线程

  • }  
  • - (void) beforeMonthChange:(TdCalendarView*) calendarView willto:(CFGregorianDate) currentMonth{  
  •     [[self calendarView] clearAllDayFlag];  
  • }  
  • /*  
  • // Only override drawRect: if you perform custom drawing.  
  • // An empty implementation adversely affects performance during animation.  
  • - (void)drawRect:(CGRect)rect {  
  •     // Drawing code.  
  • }  
  • */  
  • - (void)viewDidAppear:(BOOL)animated{  
  •     [super viewDidAppear:animated];  
  • }  
  • -(void)fetchdata{  
  •     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
  •     [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;  
  •     int maxDay = [[self calendarView] getDayCountOfaMonth:currentSelectDate];  
  •     NSString *dataURL =@"";  
  •     NSLog(@"dataURL:%@",dataURL);  
  •     NSArray *data = [JSONParser loadData:dataURL isAllValues:NO valueForKey:@"list"];  
  •     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;  
  •     [self performSelectorOnMainThread:@selector(showCount:) withObject:data waitUntilDone:NO];//通知主线程执行函数showCount
  •     [pool release];  
  • }  
  • -(void)showCount:(NSArray *)data{  
  •     int count = [data count];  
  •     NSLog(@"showChange:%d",count);  
  •     for(int i = 0;i<count-1;i++){  
  •         NSArray *bf = [data objectAtIndex:i];  
  •         if([bf valueForKey:@"day"]!=nil){  
  •             int day = [[bf valueForKey:@"day"]intValue];  
  •             int count = [[bf valueForKey:@"count"]intValue];  
  •             [calendarView setDayFlag:day flag:count];  
  •         }  
  •     }  
  •     [calendarView setNeedsDisplay];  
  • }  
  • - (void)dealloc {  
  •     [calendarView release];  
  •     [super dealloc];  
  • }  
  • @end 

 

posted @ 2015-12-28 14:22  Bo-tree  阅读(90)  评论(0)    收藏  举报