В приложении для iPhone, основанном на сигналах тревоги, я использую код TdCalenderView от tinyfool. В этом календаре я вызываю метод setDayFlag: день в drawDateWords для дня, в который установлен сигнал тревоги. При нажатии на дату открывается список сигналов тревоги для соответствующая дата.
Теперь я также использую панель вкладок в том же приложении. При нажатии на элемент 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);
}
}
Я не понимаю, почему это происходит. Любая помощь будет принята с благодарностью.