diff options
author | Nicholas Tay <nick@windblume.net> | 2022-03-14 16:32:59 +1100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-03-14 16:32:59 +1100 |
commit | 6575fcb169596a659b1a185ab53a6d27520de1d6 (patch) | |
tree | fa88784f7a67feb3e2eedfec1e535cc05ebfc9d4 /foray | |
parent | 2f22931e0a4617dbd218a92c02bc9e83649ee6f7 (diff) | |
download | forayios-6575fcb169596a659b1a185ab53a6d27520de1d6.tar.gz forayios-6575fcb169596a659b1a185ab53a6d27520de1d6.tar.bz2 forayios-6575fcb169596a659b1a185ab53a6d27520de1d6.zip |
Second type of custom cell
Not sure if this is the correct way of switching into a different cell type with the prototypes, but it works. To review.
Diffstat (limited to '')
-rw-r--r-- | foray/Base.lproj/Main.storyboard | 62 | ||||
-rw-r--r-- | foray/ForayTableViewController.swift | 33 |
2 files changed, 85 insertions, 10 deletions
diff --git a/foray/Base.lproj/Main.storyboard b/foray/Base.lproj/Main.storyboard index 7af2493..c5181ad 100644 --- a/foray/Base.lproj/Main.storyboard +++ b/foray/Base.lproj/Main.storyboard @@ -2,7 +2,8 @@ <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wzT-eD-ghF"> <device id="retina6_1" orientation="portrait" appearance="light"/> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19529"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/> + <capability name="System colors in document resources" minToolsVersion="11.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <scenes> @@ -57,6 +58,59 @@ <outlet property="cellItemSubtitle" destination="M3N-lx-IrZ" id="cXh-X9-bBs"/> </connections> </tableViewCell> + <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="ForayQuestCell" id="sac-28-Cry" customClass="ForayTableViewCell" customModule="foray" customModuleProvider="target"> + <rect key="frame" x="0.0" y="104.5" width="414" height="60"/> + <autoresizingMask key="autoresizingMask"/> + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="sac-28-Cry" id="IdU-MR-tpK"> + <rect key="frame" x="0.0" y="0.0" width="414" height="60"/> + <autoresizingMask key="autoresizingMask"/> + <subviews> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Nba-Kh-67y"> + <rect key="frame" x="20" y="11" width="265" height="24"/> + <fontDescription key="fontDescription" type="system" pointSize="20"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> + <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="spy" translatesAutoresizingMaskIntoConstraints="NO" id="ZpN-1x-wiY"> + <rect key="frame" x="335" y="11" width="59" height="38"/> + <constraints> + <constraint firstAttribute="height" constant="38" id="D8r-cM-iXE"/> + <constraint firstAttribute="width" constant="59" id="ozc-KT-4QY"/> + </constraints> + </imageView> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n6u-bY-nfG"> + <rect key="frame" x="20" y="35" width="265" height="12"/> + <fontDescription key="fontDescription" type="system" pointSize="10"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="QUEST" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mFP-n7-yqT"> + <rect key="frame" x="10" y="0.0" width="40.5" height="14.5"/> + <fontDescription key="fontDescription" type="italicSystem" pointSize="12"/> + <color key="textColor" systemColor="systemOrangeColor"/> + <nil key="highlightedColor"/> + </label> + </subviews> + <constraints> + <constraint firstItem="ZpN-1x-wiY" firstAttribute="top" secondItem="IdU-MR-tpK" secondAttribute="topMargin" id="8Jf-ts-z1R"/> + <constraint firstItem="Nba-Kh-67y" firstAttribute="leading" secondItem="IdU-MR-tpK" secondAttribute="leadingMargin" id="CAg-wX-hDK"/> + <constraint firstItem="n6u-bY-nfG" firstAttribute="top" secondItem="Nba-Kh-67y" secondAttribute="bottom" id="DIu-kt-ees"/> + <constraint firstAttribute="bottomMargin" secondItem="ZpN-1x-wiY" secondAttribute="bottom" id="RES-c1-6zK"/> + <constraint firstItem="ZpN-1x-wiY" firstAttribute="leading" secondItem="n6u-bY-nfG" secondAttribute="trailing" constant="50" id="Rf6-oe-ma3"/> + <constraint firstItem="ZpN-1x-wiY" firstAttribute="leading" secondItem="Nba-Kh-67y" secondAttribute="trailing" constant="50" id="Rk8-TC-7Zl"/> + <constraint firstAttribute="trailingMargin" secondItem="ZpN-1x-wiY" secondAttribute="trailing" id="S2Y-mc-a4w"/> + <constraint firstItem="mFP-n7-yqT" firstAttribute="leading" secondItem="IdU-MR-tpK" secondAttribute="leading" constant="10" id="SJX-QO-mMB"/> + <constraint firstItem="Nba-Kh-67y" firstAttribute="top" secondItem="IdU-MR-tpK" secondAttribute="topMargin" id="l9z-W9-Hg6"/> + <constraint firstItem="n6u-bY-nfG" firstAttribute="leading" secondItem="IdU-MR-tpK" secondAttribute="leadingMargin" id="lch-UF-tgt"/> + <constraint firstItem="mFP-n7-yqT" firstAttribute="top" secondItem="IdU-MR-tpK" secondAttribute="top" id="oi5-CN-YSA"/> + </constraints> + </tableViewCellContentView> + <connections> + <outlet property="cellItemImage" destination="ZpN-1x-wiY" id="ydK-D6-Kii"/> + <outlet property="cellItemName" destination="Nba-Kh-67y" id="lOq-hq-b38"/> + <outlet property="cellItemSubtitle" destination="n6u-bY-nfG" id="sJh-Cy-jKm"/> + </connections> + </tableViewCell> </prototypes> <sections/> <connections> @@ -70,4 +124,10 @@ <point key="canvasLocation" x="-462.31884057971018" y="51.5625"/> </scene> </scenes> + <resources> + <image name="spy" width="700" height="490"/> + <systemColor name="systemOrangeColor"> + <color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> + </systemColor> + </resources> </document> diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift index e283c9d..dc32611 100644 --- a/foray/ForayTableViewController.swift +++ b/foray/ForayTableViewController.swift @@ -7,7 +7,13 @@ import UIKit +enum ItemType { + case item + case quest +} + struct MyItem { + var type: ItemType var releaseDate: Date var id: String var name: String @@ -42,11 +48,14 @@ class ForayTableViewController: UITableViewController { // MARK: - Static data TEMP let items = [ - MyItem(releaseDate: parseDate("2006-05-26"), id: "mh", name: "Miners Helmet"), - MyItem(releaseDate: parseDate("2010-05-01"), id: "it", name: "Inner Tube"), - MyItem(releaseDate: parseDate("2009-04-24"), id: "tbg", name: "Toboggan"), - MyItem(releaseDate: parseDate("2006-03-29"), id: "spy", name: "Spy Phone"), - MyItem(releaseDate: parseDate("2008-11-18"), id: "bnb", name: "Black Ninja Belt"), + MyItem(type: .item, releaseDate: parseDate("2006-05-26"), id: "mh", name: "Miners Helmet"), + MyItem(type: .item, releaseDate: parseDate("2010-05-01"), id: "it", name: "Inner Tube"), + MyItem(type: .item, releaseDate: parseDate("2009-04-24"), id: "tbg", name: "Toboggan"), + MyItem(type: .item, releaseDate: parseDate("2006-03-29"), id: "spy", name: "Spy Phone"), + MyItem(type: .item, releaseDate: parseDate("2008-11-18"), id: "bnb", name: "Black Ninja Belt"), + MyItem(type: .quest, releaseDate: parseDate("2006-05-23"), id: "cmp", name: "Case of the Missing Puffles"), + MyItem(type: .quest, releaseDate: parseDate("2009-11-16"), id: "gsm", name: "G's Secret Mission"), + MyItem(type: .quest, releaseDate: parseDate("2009-04-18"), id: "cmc", name: "Case of the Missing Coins"), ] var sections = [YearSection]() @@ -79,12 +88,18 @@ class ForayTableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "ForayCell", for: indexPath) as! ForayTableViewCell - let item = self.sections[indexPath.section].items[indexPath.row] + let cell: ForayTableViewCell + switch item.type { + case .item: + cell = tableView.dequeueReusableCell(withIdentifier: "ForayCell", for: indexPath) as! ForayTableViewCell + cell.cellItemImage?.image = UIImage(named: item.id) + case .quest: + cell = tableView.dequeueReusableCell(withIdentifier: "ForayQuestCell", for: indexPath) as! ForayTableViewCell + } + cell.cellItemName?.text = item.name - cell.cellItemSubtitle?.text = "Item ID: \(item.id)" - cell.cellItemImage?.image = UIImage(named: item.id) + cell.cellItemSubtitle?.text = "ID: " + item.id return cell } |