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

#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 {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"比赛时间";
		//self.view.backgroundColor = [UIColor whiteColor];
		//self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back.png"]]; 
		calendarView = [[TdCalendarView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
		calendarView.backgroundColor = [UIColor whiteColor];
		//calendarView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back.png"]]; 
		[self.view addSubview:calendarView];
		[calendarView setDayFlag:15 flag:-1];
		calendarView.calendarViewDelegate = self;
    }
    return self;
}

- (void) selectDateChanged:(CFGregorianDate) selectDate{
	currentSelectDate = selectDate;
	NSLog(@"selectDateChanged catch:%d年%d月%d日",selectDate.year,selectDate.month,selectDate.day);
}
- (void) monthChanged:(CFGregorianDate) currentMonth viewLeftTop:(CGPoint)viewLeftTop height:(float)height{
	NSLog(@"monthChanged catch:%d",currentMonth.month);
	self.currentSelectDate = currentMonth;
	[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];
	[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
  大屏日历异步加载每天比赛数目并显示在日历里

你可能感兴趣的:(calendar,iPhone,比分)