CVCalendar空白但没有错误

时间:2016-08-18 22:21:25

标签: ios swift

我正在尝试使用CVCalendar pod而无法让它加载任何东西。 Xcode中没有错误消息,但我必须做错事。花了一整天试图解决这个问题。

https://github.com/Mozharovsky/CVCalendar/

1)我安装了cocoa pod并导入了CVCalendar

2)在导入下方创建2个协议 - CVCalendarViewDelegate和CVCalendarMenuViewDelegate (我觉得这可能是问题 - 以前没有与代表合作过,而且我对Xcode来说还是新手)

2)我创建了两个视图,在检查器中我将类名更改为CVCalendarMenuView和CVCalendarView

2)然后为他们创造出口。

3)然后我添加了这个

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    menuView.commitMenuViewUpdate()
    calendarView.commitCalendarViewUpdate()
}

在测试项目中,整个事情看起来像这样:

import UIKit
import CVCalendar

protocol CVCalendarViewDelegate{}
protocol CVCalendarMenuViewDelegate{}

class Test: UIViewController {

    @IBOutlet var menuView: CVCalendarMenuView!
    @IBOutlet var calendarView: CVCalendarView!

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        menuView.commitMenuViewUpdate()
        calendarView.commitCalendarViewUpdate()
    }

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

菜单视图显示为空白字段。日历视图根本不显示。没有日期没有任何按钮。

3 个答案:

答案 0 :(得分:1)

首先从https://github.com/Mozharovsky/CVCalendar/下载完整项目(推送克隆或下载按钮)。在那里,您可以找到CVCalendar开发人员的完整演示。你会有这个:

enter image description here

我修复了你的代码:

  

ViewController.swift

import UIKit
import CVCalendar

class ViewController: UIViewController, CVCalendarViewDelegate, CVCalendarMenuViewDelegate {

@IBOutlet var menuView: CVCalendarMenuView!
@IBOutlet var calendarView: CVCalendarView!

override func viewDidAppear(animated: Bool) {

    super.viewDidLoad()

    // Appearance delegate [Unnecessary]
    calendarView.calendarAppearanceDelegate = self

    // Animator delegate [Unnecessary]
    calendarView.animatorDelegate = self

    // Menu delegate [Required]
    menuView.menuViewDelegate = self

    // Calendar delegate [Required]
    calendarView.calendarDelegate = self
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    menuView.commitMenuViewUpdate()
    calendarView.commitCalendarViewUpdate()
}

override func viewDidLoad() {
    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

/// Required method to implement!
func presentationMode() -> CalendarMode {
    return .MonthView
}

/// Required method to implement!
func firstWeekday() -> Weekday {
    return .Sunday
}
}
  

Main.storyboard

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
    <deployment identifier="iOS"/>
    <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
    <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
    <!--View Controller-->
    <scene sceneID="tne-QT-ifu">
        <objects>
            <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="stackoverflow_39028382" customModuleProvider="target" sceneMemberID="viewController">
                <layoutGuides>
                    <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
                    <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
                </layoutGuides>
                <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
                    <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    <subviews>
                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KhD-VO-LEi" customClass="CVCalendarMenuView" customModule="CVCalendar">
                            <rect key="frame" x="0.0" y="28" width="600" height="57"/>
                            <color key="backgroundColor" name="controlHighlightColor" catalog="System" colorSpace="catalog"/>
                            <constraints>
                                <constraint firstAttribute="height" constant="57" id="d0p-pY-lAt"/>
                            </constraints>
                        </view>
                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8CS-QV-kqC" customClass="CVCalendarView" customModule="CVCalendar">
                            <rect key="frame" x="0.0" y="84" width="600" height="415"/>
                            <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
                            <constraints>
                                <constraint firstAttribute="height" constant="415" id="Lmo-yR-ea1"/>
                            </constraints>
                        </view>
                    </subviews>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                    <constraints>
                        <constraint firstItem="KhD-VO-LEi" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="8" id="7y9-B3-7Pg"/>
                        <constraint firstItem="8CS-QV-kqC" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="-20" id="Bce-Pi-kYh"/>
                        <constraint firstItem="8CS-QV-kqC" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="64" id="WsH-l1-nX9"/>
                        <constraint firstItem="KhD-VO-LEi" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="-20" id="ut9-R1-Exb"/>
                        <constraint firstAttribute="trailingMargin" secondItem="KhD-VO-LEi" secondAttribute="trailing" constant="-20" id="wAU-K8-TMN"/>
                        <constraint firstAttribute="trailingMargin" secondItem="8CS-QV-kqC" secondAttribute="trailing" constant="-20" id="wpf-0X-gor"/>
                    </constraints>
                </view>
                <connections>
                    <outlet property="calendarView" destination="8CS-QV-kqC" id="GND-0P-wUz"/>
                    <outlet property="menuView" destination="KhD-VO-LEi" id="inF-0o-ViY"/>
                </connections>
            </viewController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
        </objects>
    </scene>
</scenes>
</document>

此代码的结果:

enter image description here

答案 1 :(得分:0)

我认为你的错误就在这里:

protocol CVCalendarViewDelegate{}
protocol CVCalendarMenuViewDelegate{}

class Test: UIViewController {

文档并不是那么明确,但是如果说“添加这些协议”,则需要将它们添加到类中,即:

class Test: UIViewController,CVCalendarViewDelegate,CVCalendarMenuViewDelegate {

答案 2 :(得分:0)

Vasily Bodnarchuk的回答非常有效。

但是,在横向模式下,menuView的标题出现了两次。我通过将委托声明放在viewDidLoad()中而不是viewDidAppear(_ animated: Bool)中来解决了这个问题。

相关问题