2013-07-27 48 views
-1

我有一個日曆視圖控制器,它的TKCalender,並不重要。問題與安裝程序,而不是設置值

我在CalendarMonthViewController中設置了一個值,我想在另一個ViewController中調用ViewControllerInsert

CalendarMonthViewController.h

@interface CalendarMonthViewController : TKCalendarMonthTableViewController 

@property (nonatomic,strong) NSDate *dateSelected; // the value 

-(NSDate *)returnDate; // the function to fetch the value 

@end 

CalendarMonthViewController.m

- (void) calendarMonthView:(TKCalendarMonthView*)monthView didSelectDate:(NSDate*)date{ 
    NSLog(@"Date Selected: %@",date); 

    self.dateSelected = date; // set the property, at this point self.dataSelect is Valid 
    [self.tableView reloadData]; 
} 


- (NSDate *)returnDate { // function called by other viewController to get the value 

    NSDate *dateUserSelected = self.dateSelected; 

    NSLog(@"%@", self.dateSelected); // logs Null 

    return dateUserSelected; 
} 

由於它的日誌空,是空的斷點,數據是某種未設置其當被其他所謂的ViewController ?它的名字就是這樣;

- (IBAction)SeguqInsert:(id)sender { 


    CalendarMonthViewController *controller = [[CalendarMonthViewController alloc] initWithNibName:nil bundle:nil]; 

    NSDate *selectedDate = [controller returnDate]; // is clearly also Null when its null in the native method 
} 
+0

你把斷點放在self.dateSelected = date;在 - (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)日期方法? –

+2

您正在創建'controller'並立即要求'SeguqInsert:'中的'returnDate',所以'returnDate'總是返回'nil',您的'calendarMonthView:didSelectData:'中的代碼不會運行於'controller '實例。 – yonosoytu

+0

好,我將如何確保它是 –

回答

0

我覺得你

- (void) calendarMonthView:(TKCalendarMonthView*)monthView didSelectDate:(NSDate*)date 

方法不獲取調用。

通過點擊日曆中選擇任何一個日期,然後打電話給你的

- (IBAction)SeguqInsert:(id)sender 

方法。

+0

它被調用,它的日期設置正好 –

+0

您沒有爲您的實例控制器設置對象dateSelected的值。您設置的值將僅適用於CalendarMonthViewController類。 controller.dateSelected = date將爲您的實例設置該對象的值... – Avi