adding Kal Calendar as root controller for tab bar item, not using nav controller
The examples of Kal calendar controller all initialize the controller in the app delegate and push on a navigationController. I tried it and it does indeed work, however I need my calendar to be the rootController for one of my Tabbar items, which was added in the main nib.
What I tried was adding a UIViewController class as the root class in 开发者_开发百科my nib for the item, then initializing the calendar in the view controller:
KalViewController *calendar = [[KalViewController alloc] init];
[self.view addSubview:calendar];
[calendar release];
It shows up but crashes if I touch the months,days etc...
Alternatively, I made a class based on KalViewController and made that the root class for my tab bar item. But that crashes immediately without displaying.
Maybe it's possible to add the KalViewController directly into the tab bar viewController array, however I created the tab bar in the nib using the app delegate. I wouldnt know how to add it.
I recently had to do this, I left the calendar tab out of the MainWindow.xib and then in the appDelegate I grabbed the tabBarControllers list of ViewControllers loaded them in a mutableArray, inserted the KalViewController where I wanted it and then set that back into the tabBarController.
calendarDataSource = [[CalendarDataSource alloc] init];
// I had to override a few things in the calendar so I subclassed it. You get the idea though
_kalViewController = [[MyKalViewController alloc] init];
_kalViewController.dataSource = self.calendarDataSource;
_kalViewController.delegate = _kalViewController;
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:_kalViewController] autorelease];
navigationController.tabBarItem.title = @"Calendar";
navigationController.tabBarItem.image = [UIImage imageNamed:@"cal-tab.png"];
NSMutableArray *viewControllers = [self.tabBarController.viewControllers mutableCopy];
[viewControllers insertObject:navigationController atIndex:1];
self.tabBarController.viewControllers = viewControllers;
精彩评论