3
votes

Currently I have implemented the Kal calendar within one of my tabBarViewControllers and the layout is perfect. I now want to create a button that the user clicks and the calendar instantly highlights the current day in the a monthly calendar view, the button "Today".

The layout is again perfect, but the last line of code listed below gives problems.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SecondViewController showAndSelectToday]: unrecognized selector sent to instance 0x927e6f0'

Here is all the implementation I have made to my secondViewController class that is a superclass of UIViewController.

- (void)viewDidLoad 
{
    KalViewController *calendar = [[KalViewController alloc] init];
    [self.view addSubview:calendar.view];
    [self addChildViewController:calendar];
    [[self navigationController] initWithRootViewController:calendar];
    calendar.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Today" style:UIBarButtonItemStyleBordered target:self action:@selector(showAndSelectToday)];
}

Goal: Give "today" functionality NOT THROUGH THE APP DELEGATE but a seperate class, like my secondViewController.

Note: The holiday example app is exactly what I would like for "Today" to behave but the holiday example project implements the today button behaviors within the app delegate.

1

1 Answers

1
votes

You need to store the KalViewController as an instance variable (let's assume _calendar) and then implement the following method in your secondViewController:

- (void)showAndSelectToday
{
    [_calendar showAndSelectDate:[NSDate date]];
}