Reputation: 95
Background:
I am trying to create a Tinder-esque user interface that loads user profile's into stacked cards using the Koloda library - a Tinder card swiping library based off UITableView
. In the Koloda viewForCardAt()
delegate function where I am supposed to be returning a view to be inserted into the cards, I have instantiated, populated, and returned a custom xib file representing the profile cards.
The issue:
After instantiating my custom xib programmatically to be the returning view of my Koloda's viewAtCard function, and run the app, I get the following error code from Thread 1
in the first line of my AppDelegate file:
...NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X
Note: there is no error if I simply instantiate a UIImageView and just return that, so obviously something is wrong with the way I'm doing my xib...
The code:
My view controller:
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
}
}
My ProfileCard xib File: A very basic xib file containing a UIImageView and a UILabel on top. The size set to freeform, the FileOwner attribute set to 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>
My ProfileCard Swift File:
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!
}
Upvotes: 0
Views: 226