iphone - 将 Kal Calendar 添加为选项卡栏项目的根 Controller ,而不是使用导航 Controller

标签 iphone objective-c ios cocoa-touch

Kal 日历 Controller 的示例都在应用委托(delegate)中初始化 Controller 并推送到导航 Controller 上。我试过了,它确实有效,但是我需要我的日历成为我的 Tabbar 项目之一的 rootController,这是在主 Nib 中添加的。

我尝试的是在我的 Nib 中为项目添加一个 UIViewController 类作为根类,然后在 View Controller 中初始化日历:

KalViewController *calendar = [[KalViewController alloc] init];
[self.view addSubview:calendar];
[calendar release];

它会显示,但如果我触摸月份、日期等就会崩溃......

或者,我创建了一个基于 KalViewController 的类,并将其作为我的选项卡栏项目的根类。但这会立即崩溃而不会显示。

也许可以将 KalViewController 直接添加到选项卡栏 viewController 数组中,但是我使用应用程序委托(delegate)在 Nib 中创建了选项卡栏。我不知道如何添加它。

最佳答案

我最近不得不这样做,我将日历选项卡从 MainWindow.xib 中移出,然后在 appDelegate 中,我抓取了 tabBarControllers 的 ViewControllers 列表,将它们加载到 mutableArray 中,将 KalViewController 插入到我想要的位置,然后进行设置回到 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;

关于iphone - 将 Kal Calendar 添加为选项卡栏项目的根 Controller ,而不是使用导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7224810/

相关文章:

ios - 仅在解析对象比特定日期新时才更新它们吗?

iphone - 定时器不重复

iphone - iOS 7 Landscape only 应用程序无法访问照片库

iphone - 有关iOS上的本地通知和推送通知的问题

iphone - 如何从 animationDidStop 中删除 CALayer 对象?

ios - 使用带有标记更新的谷歌地图的随机崩溃

iphone - 在 Xcode 中加速 NSTimer

iphone - 如何将 UIBarButtonItem 添加到其中包含文本和图像的 UIToolbar?

iOS 定时器进度条

ios - 具有 Web + iOS 应用程序身份验证的 Rails Azure Active Directory SSO