2011-06-07 27 views
0

在我基於iPhone的鬧鐘應用程序中,我使用的是tinyfool的TdCalenderView代碼。在那個日曆中,我打電話給setDayFlag:在設置鬧鐘的那天的drawDateWords方法中的日期。觸發日期打開鬧鐘列表爲相應的日期。 現在,我也在同一個應用程序中使用Tab欄。在單擊標籤欄的項目0時,我顯示包含日曆和單擊項目1的視圖我正在顯示寫入和保存註釋的視圖。 當我寫一個筆記並保存它時,我想要在相應的日期繪製一個點。 但它沒有發生。點不在那裏。但是當我點擊一次日期時,點出現,並在第二次點擊列表顯示。 這裏是我的代碼:Redraw TdCalendarView

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); 

    } 


} 

我沒有得到這是爲什麼happening.Any幫助將不勝感激。

回答

0

好的。這可能聽起來像一個黑客,但它最終奏效。 在顯示日曆視圖和[TdCalenderView movePrevMonth]之前,我在顯示日曆視圖之後調用了[TdCalenderView moveNextMonth],並帶有一個標誌來管理當Tab Bar調用該方法時取消動畫。它刷新了我的日曆並解決了問題。