MBCalendarKit показывает черный экран в базовом приложении с вкладками
Я довольно новичок в Swift & XCode, и я использую базовый шаблон приложения с вкладками в XCode, и я пытаюсь реализовать MBCalendarKit, чтобы показать календарь на первом представлении вкладок. Я использую Cocoapods для комплекта MBCalendar. Приложение с вкладками Basic запускается со следующими файлами:
Автор MBCalendarKit объясняет, что:
"Вы можете показать экземпляр CKCalendarView. Используйте это, если вы хотите вручную управлять иерархией представления или иметь более точный контроль над представлением календаря".:
/*
Here's how you'd show a CKCalendarView from within a view controller.
It's just four easy steps.
*/
// 0. In either case, import CalendarKit:
#import "CalendarKit/CalendarKit.h"
// 1. Instantiate a CKCalendarView
CKCalendarView *calendar = [CKCalendarView new];
// 2. Optionally, set up the datasource and delegates
[calendar setDelegate:self];
[calendar setDataSource:self];
// 3. Present the calendar
[[self view] addSubview:calendar];
И я также следовал за некоторыми примерами кода, который был предоставлен, хотя большая часть была в target-c. В настоящее время при запуске программы, на первой вкладке, у меня просто черный экран. Как я могу это исправить, чтобы представить сам календарь? Я также посмотрел другие посты CalendarKit на stackru, но ни один из них, похоже, не рассматривал что-то более конкретное, чем это.
Мой FirstViewController.swift (который в основном идентичен предоставленному автором):
import UIKit
import MBCalendarKit
class FirstViewController: CKCalendarViewController, CKCalendarViewDataSource {
var data : NSMutableDictionary
required init(coder aDecoder: NSCoder) {
data = NSMutableDictionary()
super.init(coder: aDecoder)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
self.data = NSMutableDictionary()
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Step 0 : Wire up the data source and delegate
self.delegate = self
self.dataSource = self
// Step 1 : Define some test events
let title : NSString = NSLocalizedString("Some random event", comment: "")
let date : NSDate = NSDate(day: 20, month: 12, year: 2015)
let event : CKCalendarEvent = CKCalendarEvent(title: title as String, andDate: date, andInfo: nil)
// Step 2 : Add the events to the cache array
self.data[date] = [event]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//
// MARK: - CKCalendarDataSource
//
func calendarView(calendarView: CKCalendarView!, eventsForDate date: NSDate!) -> [AnyObject]! {
return self.data.objectForKey(date) as! [AnyObject]!
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
и AppDelegate.swift:
import UIKit
import MBCalendarKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var viewController: CKCalendarViewController = FirstViewController(nibName: nil, bundle: nil)
self.window!.rootViewController = viewController
self.window!.makeKeyAndVisible()
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
Также при создании FirstViewController() в файле AppDelegate я немного не был уверен в аргументах nibName и bundle. Если бы кто-то мог объяснить это, когда я пытался найти это в справочной документации Apple, но это все еще не было ясно, и для всех я знаю факт, что я пропускаю ноль для обоих, могло быть моей проблемой? Если кто-то имеет опыт работы с CalendarKit или может мне помочь, это было бы здорово,
ура