开发者

Calendar API changing

http://code.google.com/p/scm-subversion/source/browse/trunk/iPhone/CalendarTest/?r=4#CalendarTest%253Fstate%253Dclosed

I am using the above mentioned Calendar API. In CalendarTestViewController.m class we are getting the date. Now I have declared a global variable nsstring type and I want to use that date into another new class by using global variable. I have tried this a number of times but unable to get the output. If anyone know how can I use the selected date by using Calendar API, the开发者_运维知识库n please give me some solution.

Thanks in advance.

CODE

- (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{ 
NSLog(@"Date Selected is %@",[aTile date]); 
str=(NSString *)[aTile date];
} 
NSLog(@"str:%@",str); 
glbdate1 = (NSString *)[aTile date]; 
NSLog(@"glbdate1:%@",glbdate1);
} 
//I have declared the glbdate1 variable globally in app delegate file and i have made the new class calenderview 
//I want to display the date in textfield by using global variable. Here is code in calenderview

-(void)viewWillAppear:(BOOL)animated {
 if ([glbdate1 length] != 0) 
   { 
    from.text = glbdate1;
   } 
}


You have to convert the NSDate to NSString as follows,

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-mm-dd HH:mm:ss"];
NSString *dateString=[dateFormatter stringFromDate:date];

Then the same NSString value can be converted to NSDate as,

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-mm-dd HH:mm:ss"];
NSDate *dateFromString=[dateFormatter dateFromString:dateString];


 -(BOOL)isDateinEventArray:(NSString*)iDateString{

//NSString *searchText = lblDate.text;


NSMutableArray *searchArray = [[NSMutableArray alloc] init];

for (ToDo *todoObj in appDelegate.todoArray)
{
        NSString *date = todoObj.startDate;
        [searchArray addObject:date]; 
}

if ([searchArray count] > 0) {

    for (NSString *sTemp in searchArray)
    {
        NSRange titleResultsRange = [sTemp rangeOfString:iDateString 
                     options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length > 0)   
        [copyListOfItems addObject:sTemp];    
    }

    [searchArray release];
    searchArray = nil;

}

if ([copyListOfItems count] > 0) {  
    return TRUE;
}else{
    return FALSE;
}   
  }


   /*----- Calendar Delegates -----> */

  - (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{

NSLog(@"Date Selected is %@",[aTile date]);

//  NSString *stringFromDate = 
// [[NSString alloc]initWithString:[NSString stringWithFormat:@"%02i-%02i-%i",[aTile.date dayOfMonth],
//  

     [aTile.date monthOfYear],[aTile.date yearOfCommonEra]]];

NSString *stringFromDate = [[NSString alloc]initWithString:[NSString stringWithFormat:@"%02i-%02i-%02i",[aTile.date yearOfCommonEra],
                                                [aTile.date monthOfYear],[aTile.date dayOfMonth]]];


if([self isDateinEventArray:stringFromDate]){

    selectedDate = [aTile date];

    eventFoundMsg = @"Events are found on this date.";
    eventMsgTag = 1;
}else{
    eventFoundMsg = @"No events are found on this date.";
    eventMsgTag = 0;
}   
[stringFromDate release];

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Event Message" 

message:eventFoundMsg   
delegate:self
    cancelButtonTitle:@"Ok" 
    otherButtonTitles:nil]autorelease];
    alert.tag = eventMsgTag;
[alert show];
[aTile flash];
/*

if(tile == nil)
    tile = aTile;
else
    [tile restoreBackgroundColor];

 */


 }

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (eventMsgTag == 1) {

    if (buttonIndex == 0)
    {
        MyToDoView *detailViewController = [[MyToDoView alloc] 
                     initWithNibName:@"MyToDoView" bundle:nil];
        detailViewController.searchDate = selectedDate;
        NSLog([NSString stringWithFormat:@"%@",detailViewController.searchDate]);
        [detailViewController searchDateTableView];
        [self.navigationController popViewControllerAnimated:YES];
        [detailViewController release];
    }

}
}

I hope this can help you....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜