gpt4 book ai didi

ios - CVCalendar 空白但没有错误

转载 作者:行者123 更新时间:2023-11-28 16:16:21 26 4
gpt4 key购买 nike

我正在尝试使用 CVCalendar pod,但无法让它加载任何内容。 Xcode 中没有错误消息,但我一定是做错了什么。花了一整天的时间试图解决这个问题。

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

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

2) 在导入的正下方我创建了 2 个协议(protocol) - CVCalendarViewDelegate 和 CVCalendarMenuViewDelegate(我觉得这可能是问题所在 - 之前没有与代表合作过,我对 Xcode 还是很陌生)

2) 我创建了两个 View ,并在检查器中将类名更改为 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.
}
}

菜单 View 显示为空白字段。日历 View 根本不出现。没有日期,没有按钮,什么都没有。

最佳答案

首先从 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

关于ios - CVCalendar 空白但没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39028382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com