2011-12-08 13 views
0

私のアプリケーションでは、日付が含まれているテキストフィールドがあります。テキストフィールドはユーザーには編集できませんが、カレンダーでPopoverを呼び出すことができます(Tapku Calendar、BTW)。このテキストフィールドにカレンダーの選択した日付を貼り付ける必要があります。私はこのコードを試してみましたが、それは私のために働いていませんでした。 Calendar_Popover_Controller.mでポップオーバーのカレンダーからUITextFieldに値を設定できません

コード:

// grab (NSString*)Date from calendar and sending it to ChekIn field 
- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d { 

NSDate *calendarSelectedDate = [[NSDate alloc] init]; 
/* Here is formattedDate */ 

calendarSelectedDate = [calendar dateSelected]; 
DateForMainView = [formattedDate stringFromDate:calendarSelectedDate]; 

ViewController *submittedDateToMainView = [[ViewController alloc] init]; 
submittedDateToMainView.CheckInField.text = [formattedDate stringFromDate:calendarSelectedDate]; 
} 

また、私は他のバリアントをチェックしてきました。それはこのように思える:ViewController.mで

Calendar_Popover_Controller.m

- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d { 

NSDate *calendarSelectedDate = [[NSDate alloc] init];; 
/* formattedDate */ 

calendarSelectedDate = [calendar dateSelected]; 
DateForMainView = [formattedDate stringFromDate:calendarSelectedDate]; 
ViewController *submittedDateToMainView = [[ViewController alloc] init]; 
submittedDateToMainView.DateFromCalendar = DateForMainView; 
} 

コード:

ここ
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController { 
[CheckInField setText:DateFromCalendar]; 

NSLog(@"For CheckIn TextField DateFromCalendar is: %@", DateFromCalendar); 
NSLog(@"popover about to be dismissed"); 
return YES; 
} 

DateFromCalendar == nilをとにかく。私はこの問題を解決することは考えていません。

答えて

0

ViewControllerあなたはcalendarMonthView:didSelectDate:方法で使用しているが、

ViewController *submittedDateToMainView = [[ViewController alloc] init];

を行うときに、新しいものを初期化するので、あなたがあなたの既存のViewControllerへの参照を保持する必要があり、画面上に表示ものではありませんCalendar_Popover_Controllerを開き、その上にDateFromCalendarを設定してください。

+0

Thanx!私はあなたの話を理解していますが、サンプルコードを表示できますか?私はXcodeの新機能です。 – Akki

関連する問題