在iPhone上基于闹钟的应用程序中,我使用的是tinyfool的TdCalenderView代码。我在日历中调用setDayFlag:day在drawDateWords方法中设置警报的日期。触发日期打开警报列表相应的日期。 现在,我也在同一个应用程序中使用Tab栏。点击标签栏的项目0我显示包含日历的视图,点击项目1我显示了要写入和保存笔记的视图。 当我写一个笔记并保存它时,我希望在相应的日期绘制一个点。 但它没有发生。点不存在。但是当我点击日期时,点出现,第二次点击列表显示。 这是我的代码:
appdelegate.m
calendar=[[TdCalendarView alloc]init];
包含标签栏的视图
这是标签项标签的切换案例,基于我显示和隐藏视图
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.width;
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);
}
}
我不明白为什么会发生这种情况。非常感谢任何帮助。
答案 0 :(得分:0)
好的。这可能听起来像是一个黑客但最终有效。 我在显示日历视图和[TdCalenderView movePrevMonth]之前调用日历视图和[TdCalenderView movePrevMonth]之后显示日历视图,其中有一个标志来管理在Tab栏调用方法时取消动画。它刷新了我的日历并解决了问题。