0

背景:

我正在尝试创建一个 Tinder-esque 用户界面,该界面使用 Koloda 库将用户配置文件加载到堆叠卡中 - 一个基于 Tinder 卡刷卡库UITableViewviewForCardAt()在我应该返回要插入卡片的视图的 Koloda委托函数中,我已经实例化、填充并返回了一个表示配置文件卡片的自定义 xib 文件。

问题:

在以编程方式将我的自定义 xib 实例化为 Koloda 的 viewAtCard 函数的返回视图并运行应用程序后,我从Thread 1AppDelegate 文件的第一行中得到以下错误代码:

...NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X

注意:如果我只是实例化一个 UIImageView 并返回它就没有错误,所以显然我做我的 xib 的方式有问题......

编码:

我的视图控制器:

import UIKit
import Koloda
import Firebase

class HomeScreenViewController: UIViewController, KolodaViewDelegate, KolodaViewDataSource {
    //map: each card to data from userCards

    func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView {
        //render a ProfileCard given this profile's info:
        let view = Bundle.main.loadNibNamed("ProfileCard", owner: self, options: nil)?.first as! ProfileCard
        view.profileLabel.text = "personsName"
        return view
    }
}

我的 ProfileCard xib 文件:一个非常基本的 xib 文件,顶部包含一个 UIImageView 和一个 UILabel。大小设置为自由格式,FileOwner 属性设置为 ProfileCard

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
    <device id="retina6_1" orientation="portrait" appearance="light"/>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ProfileCard" customModule="MojoJojo" customModuleProvider="target">
            <connections>
                <outlet property="container" destination="iN0-l3-epB" id="NW0-eP-701"/>
                <outlet property="image" destination="AGi-0q-6ds" id="12w-8B-gwl"/>
                <outlet property="nameAge" destination="GDn-Uz-UhE" id="Wrc-ar-wbY"/>
            </connections>
        </placeholder>
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
        <view contentMode="scaleToFill" id="iN0-l3-epB">
            <rect key="frame" x="0.0" y="0.0" width="381" height="581"/>
            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
            <subviews>
                <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="AGi-0q-6ds">
                    <rect key="frame" x="0.0" y="0.0" width="381" height="582"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                </imageView>
                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GDn-Uz-UhE">
                    <rect key="frame" x="22" y="480" width="181" height="36"/>
                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
                    <nil key="textColor"/>
                    <nil key="highlightedColor"/>
                </label>
            </subviews>
            <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
            <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
            <viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
            <point key="canvasLocation" x="-51" y="504"/>
        </view>
    </objects>
</document>

我的 ProfileCard Swift 文件:

import UIKit

//the 'controller'
class ProfileCard: UIView {
    //reference to image in the profile card
    @IBOutlet weak var imageElement: UIImageView!
    //reference to the name and age label
    @IBOutlet weak var nameAgeLabel: UILabel!
}
4

0 回答 0