Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
xai3 committed Mar 29, 2016
2 parents 55f7513 + b98c25e commit c5fc0ad
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Classes/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class Row<T: UITableViewCell>: RowType {
public typealias RowInformation = (row: Row<T>, tableView: UITableView, indexPath: NSIndexPath)
public typealias RowMoveInformation = (row: Row<T>, tableView: UITableView, sourceIndexPath: NSIndexPath, destinationIndexPath: NSIndexPath)

init() { }
public init() { }

init(@noescape closure: (Row<T> -> Void)) {
public init(@noescape closure: (Row<T> -> Void)) {
closure(self)
}

Expand Down
6 changes: 3 additions & 3 deletions Classes/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ extension Section {
}

public func createHeader(@noescape closure: (SectionHeaderFooter<HeaderType> -> Void)) -> Self {
return createHaederFooter { (header: SectionHeaderFooter<HeaderType>) in
return createHeaderFooter { (header: SectionHeaderFooter<HeaderType>) in
self.header = header
closure(header)
}
}

public func createFooter(@noescape closure: (SectionHeaderFooter<FooterType> -> Void)) -> Self {
return createHaederFooter { (footer: SectionHeaderFooter<FooterType>) in
return createHeaderFooter { (footer: SectionHeaderFooter<FooterType>) in
self.footer = footer
closure(footer)
}
}

private func createHaederFooter<T>(@noescape closure:(SectionHeaderFooter<T> -> Void)) -> Self {
private func createHeaderFooter<T>(@noescape closure:(SectionHeaderFooter<T> -> Void)) -> Self {
closure(SectionHeaderFooter<T>())
return self
}
Expand Down
8 changes: 7 additions & 1 deletion Classes/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Source: NSObject {
closure(self)
}

var didMoveRow: ((NSIndexPath, NSIndexPath) -> Void)?
public var didMoveRow: ((NSIndexPath, NSIndexPath) -> Void)?

public func addSection(section: SectionType) -> Self {
sections.append(section)
Expand Down Expand Up @@ -227,13 +227,19 @@ extension Source {
if let delegate = headerFooter as? SectionHeaderFooterDelegateType {
delegate.configureView(tableView, view: view, section: section)
}
if let cell = view as? UITableViewCell {
return cell.contentView
}
return view
}

// Create view
if let delegate = headerFooter as? SectionHeaderFooterDelegateType,
let view = delegate.viewFor(tableView, section: section) {
delegate.configureView(tableView, view: view, section: section)
if let cell = view as? UITableViewCell {
return cell.contentView
}
return view
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

**Shoyu** is a library written in Swift to represent UITableView data structures.

Shoyu means Soy Source in Japanese.
Shoyu means Soy Sauce in Japanese.

## Usege

Expand Down
28 changes: 14 additions & 14 deletions ShoyuExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="t4g-cc-eZI">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="14F1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="t4g-cc-eZI">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand All @@ -26,7 +26,7 @@
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="SoySource" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="ShoyuExample" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
Expand Down Expand Up @@ -61,7 +61,7 @@
<!--Table View Controller-->
<scene sceneID="9ds-e3-SbW">
<objects>
<viewController id="6Ld-bI-o9t" customClass="TableViewController" customModule="SoySource" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="6Ld-bI-o9t" customClass="TableViewController" customModule="ShoyuExample" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="mtC-QN-xfQ"/>
<viewControllerLayoutGuide type="bottom" id="vco-mC-5Z5"/>
Expand All @@ -70,16 +70,16 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="62" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="WCw-e7-drD" customClass="TableView" customModule="SoySource" customModuleProvider="target">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="62" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="WCw-e7-drD" customClass="TableView" customModule="ShoyuExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="DefaultTableViewCell" rowHeight="62" id="bPZ-RK-Mn4" customClass="DefaultTableViewCell" customModule="SoySource" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="DefaultTableViewCell" rowHeight="62" id="bPZ-RK-Mn4" customClass="DefaultTableViewCell" customModule="ShoyuExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="92" width="320" height="62"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="bPZ-RK-Mn4" id="f10-dc-rCW">
<rect key="frame" x="0.0" y="0.0" width="320" height="61.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="61"/>
<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="D9W-bY-JyK">
Expand All @@ -101,15 +101,15 @@
<outlet property="nameLabel" destination="D9W-bY-JyK" id="N6K-Eu-iGB"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Header" rowHeight="38" id="RHC-X7-OVv">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Header" rowHeight="38" id="RHC-X7-OVv" customClass="HeaderTableViewCell" customModule="ShoyuExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="154" width="320" height="38"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="RHC-X7-OVv" id="oZh-UC-GT0">
<rect key="frame" x="0.0" y="0.0" width="320" height="37.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Header" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="E4v-Jc-jMZ">
<rect key="frame" x="15" y="8.5" width="56" height="20.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Header" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="E4v-Jc-jMZ">
<rect key="frame" x="15" y="9" width="56" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
Expand All @@ -122,15 +122,15 @@
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Footer" rowHeight="38" id="QEu-1h-kwL">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Footer" rowHeight="38" id="QEu-1h-kwL" customClass="FooterTableViewCell" customModule="ShoyuExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="192" width="320" height="38"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="QEu-1h-kwL" id="YkE-Xg-GVk">
<rect key="frame" x="0.0" y="0.0" width="320" height="37.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Footer" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8yd-ps-hcm">
<rect key="frame" x="15" y="8.5" width="56" height="20.5"/>
<rect key="frame" x="15" y="9" width="56" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
Expand Down
39 changes: 21 additions & 18 deletions ShoyuExample/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ class TableViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
tableView.source = Source().createSection { (section: Section) in
tableView.source = Source().createSection { (section: Section<HeaderTableViewCell, FooterTableViewCell>) in
section.createHeader { header in
header.reuseIdentifier = "Header"
header.height = 32
header.configureView = { event in
event.view.backgroundColor = UIColor.blueColor()
header.configureView = { headerCell, _ in
headerCell.contentView.backgroundColor = UIColor.blueColor()
}
}
section.createFooter { footer in
footer.createView = { [weak self] _ in
return self?.createView()
return self?.createViewForFooterCell()
}
footer.configureView = { event in
event.view.backgroundColor = UIColor.orangeColor()
footer.configureView = { footerCell, _ in
footerCell.contentView.backgroundColor = UIColor.orangeColor()
}
footer.titleFor = { _ -> String? in
return "footer"
Expand Down Expand Up @@ -80,21 +80,21 @@ class TableViewController: UIViewController {
tableView.setEditing(true, animated: true)
}

private func configureMemberCell<T: DefaultTableViewCell>(member: Member) -> Row<T>.RowCellEventType -> Void {
return { event in
event.cell.setupWith(DefaultTableViewCellModel(name: member))
private func configureMemberCell<T: DefaultTableViewCell>(member: Member) -> (T, Row<T>.RowInformation) -> Void {
return { cell, _ in
cell.setupWith(DefaultTableViewCellModel(name: member))
}
}

private func didSelectMember<T>(member: Member) -> Row<T>.RowEventType -> Void {
return { [weak self] event in
private func didSelectMember<T>(member: Member) -> Row<T>.RowInformation -> Void {
return { [weak self] _ in
self?.memberSelected(member)
}
}

private func configureCountCell<T: DefaultTableViewCell>(index: UInt) -> Row<T>.RowCellEventType -> Void {
return { event in
event.cell.nameLabel.text = String(index)
private func configureCountCell<T: DefaultTableViewCell>(index: UInt) -> (T, Row<T>.RowInformation) -> Void {
return { cell, _ in
cell.nameLabel.text = String(index)
}
}

Expand All @@ -106,13 +106,13 @@ class TableViewController: UIViewController {
print("TableViewController deinit")
}

private func createView() -> UIView {
let view = UIView()
private func createViewForFooterCell() -> FooterTableViewCell {
let cell = FooterTableViewCell()
let label = UILabel(frame: CGRectMake(5, 5, 0, 0))
label.text = "Custom view footer"
label.sizeToFit()
view.addSubview(label)
return view
cell.contentView.addSubview(label)
return cell
}

}
Expand All @@ -129,6 +129,9 @@ class DefaultTableViewCell: UITableViewCell {
}
}

class HeaderTableViewCell: UITableViewCell { }
class FooterTableViewCell: UITableViewCell { }

struct DefaultTableViewCellModel {
var name: NameProtocol

Expand Down

0 comments on commit c5fc0ad

Please sign in to comment.