Skip to content

Commit

Permalink
add mapping for storyboard cells
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Jan 10, 2016
1 parent 4c12a4b commit c94f721
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [4.5.3](https://github.com/DenHeadless/DTTableViewManager/releases/tag/4.5.0)

## Fixed

* Fixed a bug, where prototype cell from storyboard could not be created after calling `registerCellClass(_:)` method.

## [4.5.0](https://github.com/DenHeadless/DTTableViewManager/releases/tag/4.5.0)

## Added
Expand Down
2 changes: 1 addition & 1 deletion DTTableViewManager.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'DTTableViewManager'
s.version = '4.5.2'
s.version = '4.5.3'
s.license = 'MIT'
s.summary = 'Protocol-oriented UITableView management, powered by generics and associated types.'
s.homepage = 'https://github.com/DenHeadless/DTTableViewManager'
Expand Down
5 changes: 4 additions & 1 deletion DTTableViewManager/Sources/TableViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class TableViewFactory
let reuseIdentifier = String(T)
if tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) == nil
{
// Storyboard prototype cell
self.tableView.registerClass(T.self, forCellReuseIdentifier: reuseIdentifier)

if UINib.nibExistsWithNibName(reuseIdentifier, inBundle: bundle) {
Expand All @@ -77,6 +76,10 @@ class TableViewFactory
mappings.addMappingForViewType(.Cell, viewClass: T.self)
}
}
else {
// Storyboard prototype cell
mappings.addMappingForViewType(.Cell, viewClass: T.self)
}
}

func registerNibNamed<T:ModelTransfer where T: UITableViewCell>(nibName : String, forCellClass cellClass: T.Type)
Expand Down
24 changes: 24 additions & 0 deletions Example/DTTableViewManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
9A26E00C1C3C4C4700108443 /* SectionModel+HeaderFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A26E0091C3C4C4700108443 /* SectionModel+HeaderFooter.swift */; };
9A26E00D1C3C4C4700108443 /* UIView+XibLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A26E00A1C3C4C4700108443 /* UIView+XibLoading.swift */; };
9A26E00E1C3C4C4700108443 /* UIView+XibLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A26E00A1C3C4C4700108443 /* UIView+XibLoading.swift */; };
9A2C58101C42B2820047AAB4 /* FixtureStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A2C580F1C42B2820047AAB4 /* FixtureStoryboard.storyboard */; };
9A2C58111C42B2820047AAB4 /* FixtureStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A2C580F1C42B2820047AAB4 /* FixtureStoryboard.storyboard */; };
9A2C581B1C42B2A60047AAB4 /* StoryboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2C581A1C42B2A60047AAB4 /* StoryboardViewController.swift */; };
9A2C581C1C42B2A60047AAB4 /* StoryboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2C581A1C42B2A60047AAB4 /* StoryboardViewController.swift */; };
9A2C581E1C42B2E60047AAB4 /* StoryboardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2C581D1C42B2E60047AAB4 /* StoryboardCell.swift */; };
9A2C581F1C42B2E60047AAB4 /* StoryboardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2C581D1C42B2E60047AAB4 /* StoryboardCell.swift */; };
9A2C58211C42B3870047AAB4 /* StoryboardMappingTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2C58201C42B3870047AAB4 /* StoryboardMappingTestCase.swift */; };
9A2C58221C42B3870047AAB4 /* StoryboardMappingTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2C58201C42B3870047AAB4 /* StoryboardMappingTestCase.swift */; };
9A41FBDB1B8A176300508207 /* BankCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A41FBDA1B8A176300508207 /* BankCell.xib */; };
9A41FBE01B8A17C400508207 /* Banks.json in Resources */ = {isa = PBXBuildFile; fileRef = 9A41FBDF1B8A17C400508207 /* Banks.json */; };
9A41FBE31B8A17E700508207 /* mochaGrunge.png in Resources */ = {isa = PBXBuildFile; fileRef = 9A41FBE11B8A17E700508207 /* mochaGrunge.png */; };
Expand Down Expand Up @@ -246,6 +254,10 @@
9A26E00A1C3C4C4700108443 /* UIView+XibLoading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+XibLoading.swift"; path = "Sources/UIView+XibLoading.swift"; sourceTree = "<group>"; };
9A2A38BC1AEE285E0021E97D /* DTTableViewManager.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DTTableViewManager.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9A2A38BF1AEE285E0021E97D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = DTTableViewManager/Info.plist; sourceTree = "<group>"; };
9A2C580F1C42B2820047AAB4 /* FixtureStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = FixtureStoryboard.storyboard; path = Fixtures/FixtureStoryboard.storyboard; sourceTree = "<group>"; };
9A2C581A1C42B2A60047AAB4 /* StoryboardViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardViewController.swift; sourceTree = "<group>"; };
9A2C581D1C42B2E60047AAB4 /* StoryboardCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardCell.swift; sourceTree = "<group>"; };
9A2C58201C42B3870047AAB4 /* StoryboardMappingTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardMappingTestCase.swift; sourceTree = "<group>"; };
9A41FBDA1B8A176300508207 /* BankCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = BankCell.xib; path = Cells/BankCell.xib; sourceTree = "<group>"; };
9A41FBDF1B8A17C400508207 /* Banks.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Banks.json; path = "Example controllers/Search/Banks.json"; sourceTree = "<group>"; };
9A41FBE11B8A17E700508207 /* mochaGrunge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = mochaGrunge.png; path = Resources/mochaGrunge.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -447,6 +459,9 @@
9AF931541B5936A800456503 /* OptionalCells.swift */,
9A9793B21B5BDA7A00908C72 /* ReactingTableCell.swift */,
9A244A1D1B6134B0007E4FAA /* ReactingHeaderFooters.swift */,
9A2C580F1C42B2820047AAB4 /* FixtureStoryboard.storyboard */,
9A2C581D1C42B2E60047AAB4 /* StoryboardCell.swift */,
9A2C581A1C42B2A60047AAB4 /* StoryboardViewController.swift */,
);
name = Cells;
sourceTree = "<group>";
Expand Down Expand Up @@ -546,6 +561,7 @@
9A1A49A01B54555D0006610B /* Fixtures */,
9A1A499C1B54527E0006610B /* CreationTestCase.swift */,
9A75CEC01B55AE6F007FB06C /* MappingTestCase.swift */,
9A2C58201C42B3870047AAB4 /* StoryboardMappingTestCase.swift */,
9A52DD6A1B5A99F30048F535 /* DatasourceTestCase.swift */,
9A9793B41B5BDB4400908C72 /* ReactingToEventsTestCase.swift */,
9AD92BEF1BE27AEA00E667FF /* DelegateForwardingTestCase.swift */,
Expand Down Expand Up @@ -824,6 +840,7 @@
9A6CEDA91BE573930091B0AF /* NibCell.xib in Resources */,
9A6CEDA31BE572B90091B0AF /* NibView.xib in Resources */,
9A6CEDAE1BE573E40091B0AF /* ReactingHeaderFooterView.xib in Resources */,
9A2C58111C42B2820047AAB4 /* FixtureStoryboard.storyboard in Resources */,
9A6CEDAC1BE573C50091B0AF /* RandomNibNameCell.xib in Resources */,
9A6CEDA71BE573080091B0AF /* XibTableViewController.xib in Resources */,
);
Expand Down Expand Up @@ -853,6 +870,7 @@
9A952DFF1B567BE900B9255E /* NibCell.xib in Resources */,
9A952E041B56832100B9255E /* RandomNibNameCell.xib in Resources */,
9A71EDC01B61481300047DE0 /* ReactingHeaderFooterView.xib in Resources */,
9A2C58101C42B2820047AAB4 /* FixtureStoryboard.storyboard in Resources */,
9A1663ED1B5A68B200B2C3C8 /* NibView.xib in Resources */,
9A1663EF1B5A68BE00B2C3C8 /* NibHeaderFooterView.xib in Resources */,
);
Expand Down Expand Up @@ -884,8 +902,11 @@
9AC48D671C0B309D00531260 /* ViewModelMappingCustomizableTestCase.swift in Sources */,
9A6CED621BE570750091B0AF /* FixtureViews.swift in Sources */,
9A6CED631BE570750091B0AF /* DatasourceTestCase.swift in Sources */,
9A2C58221C42B3870047AAB4 /* StoryboardMappingTestCase.swift in Sources */,
9A2C581C1C42B2A60047AAB4 /* StoryboardViewController.swift in Sources */,
9A6CED641BE570750091B0AF /* MappingTestCase.swift in Sources */,
9A6CED651BE570750091B0AF /* ReactingToEventsTestCase.swift in Sources */,
9A2C581F1C42B2E60047AAB4 /* StoryboardCell.swift in Sources */,
9A6CED661BE570750091B0AF /* ReactingHeaderFooters.swift in Sources */,
9A6CED671BE570750091B0AF /* ReactingTableCell.swift in Sources */,
9A6CED681BE570750091B0AF /* OptionalCells.swift in Sources */,
Expand Down Expand Up @@ -940,8 +961,11 @@
9AC48D661C0B309D00531260 /* ViewModelMappingCustomizableTestCase.swift in Sources */,
9A1663EB1B5A63CA00B2C3C8 /* FixtureViews.swift in Sources */,
9A52DD6B1B5A99F30048F535 /* DatasourceTestCase.swift in Sources */,
9A2C58211C42B3870047AAB4 /* StoryboardMappingTestCase.swift in Sources */,
9A2C581B1C42B2A60047AAB4 /* StoryboardViewController.swift in Sources */,
9A75CEC11B55AE6F007FB06C /* MappingTestCase.swift in Sources */,
9A9793B51B5BDB4400908C72 /* ReactingToEventsTestCase.swift in Sources */,
9A2C581E1C42B2E60047AAB4 /* StoryboardCell.swift in Sources */,
9A244A1E1B6134B0007E4FAA /* ReactingHeaderFooters.swift in Sources */,
9A9793B31B5BDA7A00908C72 /* ReactingTableCell.swift in Sources */,
9AF931551B5936A800456503 /* OptionalCells.swift in Sources */,
Expand Down
63 changes: 63 additions & 0 deletions Example/XCTests/Fixtures/FixtureStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="jtA-Is-IGf">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--Storyboard View Controller-->
<scene sceneID="9I6-gG-AK5">
<objects>
<viewController id="jtA-Is-IGf" customClass="StoryboardViewController" customModule="Tests_iOS" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="MaC-Aq-h72"/>
<viewControllerLayoutGuide type="bottom" id="amm-Xz-GQN"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Xek-1O-YQZ">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="zb1-Gc-1Ri">
<rect key="frame" x="0.0" y="20" width="600" height="580"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="StoryboardCell" id="Nrx-9s-Wv0" customClass="StoryboardCell" customModule="Tests_iOS" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Nrx-9s-Wv0" id="zT7-ij-Fmy">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<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="1yW-mB-mqz">
<rect key="frame" x="159" y="8" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="storyboardLabel" destination="1yW-mB-mqz" id="zMx-nm-zSm"/>
</connections>
</tableViewCell>
</prototypes>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="zb1-Gc-1Ri" firstAttribute="top" secondItem="MaC-Aq-h72" secondAttribute="bottom" id="NAh-yl-tor"/>
<constraint firstItem="zb1-Gc-1Ri" firstAttribute="leading" secondItem="Xek-1O-YQZ" secondAttribute="leading" id="Nqh-Jq-jhY"/>
<constraint firstAttribute="trailing" secondItem="zb1-Gc-1Ri" secondAttribute="trailing" id="jk2-LL-Lr3"/>
<constraint firstItem="amm-Xz-GQN" firstAttribute="top" secondItem="zb1-Gc-1Ri" secondAttribute="bottom" id="yqA-iS-aHR"/>
</constraints>
</view>
<connections>
<outlet property="tableView" destination="zb1-Gc-1Ri" id="lfw-48-Rzn"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="2kJ-GB-9l1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="751" y="560"/>
</scene>
</scenes>
</document>
18 changes: 18 additions & 0 deletions Example/XCTests/StoryboardCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// StoryboardCell.swift
// DTTableViewManager
//
// Created by Denys Telezhkin on 10.01.16.
// Copyright © 2016 Denys Telezhkin. All rights reserved.
//

import UIKit
import DTModelStorage

class StoryboardCell : UITableViewCell, ModelTransfer
{
@IBOutlet weak var storyboardLabel: UILabel!
func updateWithModel(model: Int) {

}
}
35 changes: 35 additions & 0 deletions Example/XCTests/StoryboardMappingTestCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// StoryboardMappingTestCase.swift
// DTTableViewManager
//
// Created by Denys Telezhkin on 10.01.16.
// Copyright © 2016 Denys Telezhkin. All rights reserved.
//

import UIKit
import XCTest
import Nimble
import DTModelStorage
@testable import DTTableViewManager

class StoryboardMappingTestCase: XCTestCase {

var controller : StoryboardViewController!

override func setUp() {
super.setUp()
let storyboard = UIStoryboard(name: "FixtureStoryboard", bundle: NSBundle(forClass: self.dynamicType))
controller = storyboard.instantiateInitialViewController() as! StoryboardViewController
_ = controller.view
controller.manager.startManagingWithDelegate(controller)
}

func testCellIsMappedAndOutletsAreCreated() {
controller.manager.registerCellClass(StoryboardCell)
controller.manager.memoryStorage.addItem(1)

let cell = controller.manager.tableView(controller.tableView, cellForRowAtIndexPath: indexPath(0, 0)) as! StoryboardCell

expect(cell.storyboardLabel).toNot(beNil())
}
}
15 changes: 15 additions & 0 deletions Example/XCTests/StoryboardViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// StoryboardViewController.swift
// DTTableViewManager
//
// Created by Denys Telezhkin on 10.01.16.
// Copyright © 2016 Denys Telezhkin. All rights reserved.
//

import UIKit
import DTTableViewManager

class StoryboardViewController: UIViewController, DTTableViewManageable {

@IBOutlet weak var tableView: UITableView!
}

0 comments on commit c94f721

Please sign in to comment.