2011-07-25 11 views
0

http://code.google.com/p/scm-subversion/source/browse/trunk/iPhone/CalendarTest/?r=4#CalendarTest%253Fstate%253DclosedカレンダーAPIの変更

私は上記のカレンダーAPIを使用しています。 CalendarTestViewController.mクラスでは、日付を取得しています。今では、グローバル変数nsstring型を宣言しました。グローバル変数を使用して、その日付を別の新しいクラスに使用したいと考えています。私はこれを数回試しましたが、出力を得ることができませんでした。誰かがCalendar APIを使用して選択した日付を使用する方法を知っている場合は、私にいくつかの解決策を教えてください。

ありがとうございます。

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; 
    } 
} 
+0

uはしようとしたHAVワットのいくつかのコードを追加します。.. – KingofBliss

+0

- (無効)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile { \tのNSLog(@ "選択された日付は%@"、[aTile日付]); \t str =(NSString *)[aTile date];} \t NSLog(@ "str:%@"、str); \t \t glbdate1 =(NSString *)[aTile date];私はglbdate1変数をアプリケーションデリゲートファイルでグローバルに宣言しました。新しいクラスcalenderviewを作成しました。グローバル変数を使用してテキストフィールドに日付を表​​示したいのですが。ここでは、calenderviewのコードです - (void)viewWillAppear:(BOOL)animated { if([glbdate1 length]!= 0){ \t from.text = glbdate1; } –

答えて

1

あなたは次のようにNSStringのにNSDateを変換する必要があり、その後、同じNSStringの値としてNSDateに変換することができ

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

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-mm-dd HH:mm:ss"]; 
NSDate *dateFromString=[dateFormatter dateFromString:dateString]; 
1
-(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]; 
    } 

} 
} 
私は、これはあなたを助けることができると思います

....

関連する問題