Redraw TdCalendarView
In my alarm based application on iPhone,I am using TdCalenderView code by tinyfool.On that calendar I am calling setDayFlag:day in drawDateWords method for the day on which alarm is set.Tapping the date opens the list of alarms for the corresponding date. Now,I am also using Tab bar in the same application.On clicking item 0 of tab bar I am showing view containing calendar and on clicking item 1 I am showing the view to write and save the note. When I am writing a note and saving it,I want a point to be plotted on corresponding date. But it doesn't happen.The point is not there.But when I tap once on the date,the point appears and on second tap the list is shown. Here is my code:
appdelegate.m
calendar=[[TdCalendarView alloc]init];
View containing tab bar
this is switch case for tab item tags based on which I am showing and hiding the views
switch (tag) {
case 0:
WriteANoteView.hidden=YES;
RecordANoteView.hidden=YES;
BirthdayView.hidden=YES;
AllNotesView.hidden=NO;
app.calendar initCalView];
[app.calendar drawDateWords];
break;
TdCalendarView.m
-(void)initCalView{
currentTime=CFAbsoluteTimeGetCurrent();
currentMonthDate=CFAbsoluteTimeGetGregorianDate(currentTime,CFTimeZoneCopyDefault());
currentMonthDate.day=1;
currentSelectDate.year=0;
monthFlagArray=malloc(sizeof(int)*93);
[self clearAllDayFlag];
app=(Note_TakerAppDelegate *)[[UIApplication sharedApplication] delegate];
[app getWrittenNotesAndDates];
app.calendar.tableContentArray=[[NSMutableArray alloc]init];
app.calendar.tableRDatesArray=[[NSMutableArray alloc]init];
app.calendar.tableCrDatesArray=[[NSMutableArray alloc]init];
}
-(void)drawDateWords{
CGContextRef ctx=UIGraphicsGetCurrentContext();
int width=self.frame.size.w开发者_运维知识库idth;
int dayCount=[self getDayCountOfaMonth:currentMonthDate];
int day=0;
int x=0;
int y=0;
int s_width=width/7;
int curr_Weekday=[self getMonthWeekday:currentMonthDate];
UIFont *weekfont=[UIFont boldSystemFontOfSize:12];
for(int i=1;i<dayCount+1;i++)
{
day=i+curr_Weekday-2;
x=day % 7;
y=day / 7;
NSString *date=[[[NSString alloc] initWithFormat:@"%2d",i] autorelease];
[date drawAtPoint:CGPointMake(x*s_width+15,y*itemHeight+headHeight)withFont:weekfont];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
for(int j=0;j<[app.datesofTextArray count];j++)
{
if([[NSString stringWithFormat:@"%@",[app.datesofTextArray objectAtIndex:j]] length] !=0)
{
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss"];
NSDate *dateFromString=[dateFormatter dateFromString:[NSString stringWithFormat:@"%@",[app.datesofTextArray objectAtIndex:j]]];
[dateFormatter setDateFormat:@"dd"];
int day1=[[dateFormatter stringFromDate:dateFromString]intValue];
[dateFormatter setDateFormat:@"MM"];
int month1=[[dateFormatter stringFromDate:dateFromString]intValue];
[dateFormatter setDateFormat:@"yyyy"];
int year1=[[dateFormatter stringFromDate:dateFromString]intValue];
if(day1==day && month1==currentMonthDate.month && year1==currentMonthDate.year)
{
NSLog(@"in if rdate day1=%d,month1=%d,year1=%d",day1,month1,year1);
[self setDayFlag:day flag:1];
[self paintDot:day];
}
}
else
{
//NSLog(@"in else date=%@",[app.datesofTextArray objectAtIndex:i]);
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss"];
NSDate *dateFromString=[dateFormatter dateFromString:[NSString stringWithFormat:@"%@",[app.creationDates objectAtIndex:j]]];
[dateFormatter setDateFormat:@"dd"];
int day1=[[dateFormatter stringFromDate:dateFromString]intValue];
[dateFormatter setDateFormat:@"MM"];
int month1=[[dateFormatter stringFromDate:dateFromString]intValue];
[dateFormatter setDateFormat:@"yyyy"];
int year1=[[dateFormatter stringFromDate:dateFromString]intValue];
if(day1==day && month1==currentMonthDate.month && year1==currentMonthDate.year)
{
NSLog(@"in if cdate day1=%d,month1=%d,year1=%d",day1,month1,year1);
[self setDayFlag:day flag:1];
[self paintDot:day];
}
}
}
[dateFormatter release];
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1);
}
}
I am not getting why this is happening.Any help would be greatly appreciated.
Ok.This may sound like a hack but it eventually worked. I called [TdCalenderView moveNextMonth] before showing calendar view and [TdCalenderView movePrevMonth] after showing the calendar view with a flag to manage cancelling the animation when the method is invoked by Tab bar.It refreshed my calendar and issue is resolved.
精彩评论