Skip to content

Commit

Permalink
Merge pull request #7 from pavankataria/ImplementDataSource
Browse files Browse the repository at this point in the history
Implements Data Source
  • Loading branch information
pavankataria authored Apr 6, 2017
2 parents ef1cb17 + aecad09 commit 9115efb
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 21 deletions.
11 changes: 11 additions & 0 deletions Example/SwiftDataTables.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
058D4BB71E954000002A2DC9 /* DataTableWithDataSourceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 058D4BB61E954000002A2DC9 /* DataTableWithDataSourceViewController.swift */; };
05DDE6B11E71AF2C003BD61E /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05DDE6B01E71AF2C003BD61E /* File.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
Expand All @@ -29,6 +30,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
058D4BB21E953FDD002A2DC9 /* SwiftDataTables_Example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SwiftDataTables_Example-Bridging-Header.h"; sourceTree = "<group>"; };
058D4BB61E954000002A2DC9 /* DataTableWithDataSourceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTableWithDataSourceViewController.swift; sourceTree = "<group>"; };
05DDE6B01E71AF2C003BD61E /* File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
5076460E54A93B08419E4FC3 /* Pods_SwiftDataTables_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftDataTables_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
50B52C9654BFE2DA84A4C929 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -109,10 +112,12 @@
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
05DDE6B01E71AF2C003BD61E /* File.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
058D4BB61E954000002A2DC9 /* DataTableWithDataSourceViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
058D4BB21E953FDD002A2DC9 /* SwiftDataTables_Example-Bridging-Header.h */,
);
name = "Example for SwiftDataTables";
path = SwiftDataTables;
Expand Down Expand Up @@ -368,6 +373,7 @@
files = (
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
05DDE6B11E71AF2C003BD61E /* File.swift in Sources */,
058D4BB71E954000002A2DC9 /* DataTableWithDataSourceViewController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -503,13 +509,16 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = R85C7FUGTC;
INFOPLIST_FILE = SwiftDataTables/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftDataTables/SwiftDataTables_Example-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -521,13 +530,15 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = R85C7FUGTC;
INFOPLIST_FILE = SwiftDataTables/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SwiftDataTables/SwiftDataTables_Example-Bridging-Header.h";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
105 changes: 94 additions & 11 deletions Example/SwiftDataTables/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,111 @@
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Table View Controller-->
<scene sceneID="eNq-Yj-i8z">
<objects>
<tableViewController id="pBx-VP-LkD" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="eY3-7a-GXO">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<sections>
<tableViewSection id="0ui-Ru-kje">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="gjw-Ec-f5i" rowHeight="100" style="IBUITableViewCellStyleDefault" id="CH5-PX-2ia">
<rect key="frame" x="0.0" y="0.0" width="768" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="CH5-PX-2ia" id="WZU-xY-seD">
<rect key="frame" x="0.0" y="0.0" width="702" height="99"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Initialised With Data Set" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="gjw-Ec-f5i">
<rect key="frame" x="48" y="0.0" width="654" height="99"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Fvs-Bl-BcX" kind="show" id="Ib0-OY-5DL"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="aAg-kV-a5d" rowHeight="100" style="IBUITableViewCellStyleDefault" id="hzo-5s-eGE">
<rect key="frame" x="0.0" y="100" width="768" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hzo-5s-eGE" id="TtX-It-voX">
<rect key="frame" x="0.0" y="0.0" width="702" height="99"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Initialised with Data source" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="aAg-kV-a5d">
<rect key="frame" x="48" y="0.0" width="654" height="99"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="zID-PT-69B" kind="show" id="vCk-MJ-7h0"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="pBx-VP-LkD" id="Kea-0l-bHA"/>
<outlet property="delegate" destination="pBx-VP-LkD" id="vYW-cb-Mbq"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="S9L-j2-JTF"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="UsY-d7-Lxa" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="816" y="139"/>
</scene>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<scene sceneID="ePO-4E-mwJ">
<objects>
<viewController id="Fvs-Bl-BcX" customClass="ViewController" customModule="SwiftDataTables_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="kl0-0Q-qwd"/>
<viewControllerLayoutGuide type="bottom" id="lBl-1f-fNu"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Eg3-fI-0Yn">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="V3i-1E-Jkn" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1680" y="-156"/>
</scene>
<!--Data Table With Data Source View Controller-->
<scene sceneID="KDC-tH-a2r">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="SwiftDataTables_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="zID-PT-69B" customClass="DataTableWithDataSourceViewController" customModule="SwiftDataTables_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
<viewControllerLayoutGuide type="top" id="3lz-zG-RCu"/>
<viewControllerLayoutGuide type="bottom" id="C39-oY-bx2"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<view key="view" contentMode="scaleToFill" id="zYd-bK-yxK">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="HAW-IE-N30"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="6iz-8H-Jf8" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="905.46875" y="138.8671875"/>
<point key="canvasLocation" x="1680" y="483"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="H1t-3u-Z0T">
Expand All @@ -38,7 +121,7 @@
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="JZ2-k7-tEX"/>
<segue destination="pBx-VP-LkD" kind="relationship" relationship="rootViewController" id="n8e-5k-Xgf"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mvO-wT-vHi" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// DataTableWithDataSourceViewController.swift
// SwiftDataTables
//
// Created by Pavan Kataria on 05/04/2017.
// Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import SwiftDataTables

class DataTableWithDataSourceViewController: UIViewController {

var dataTable: SwiftDataTable! = nil
var dataSource: DataTableContent = []

let headerTitles = ["Name", "Fav Beverage", "Fav language", "Short term goals", "Height"]

override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
self.navigationController?.navigationBar.isTranslucent = false
self.title = "Streaming fans"
self.view.backgroundColor = UIColor.white

self.dataTable = SwiftDataTable(dataSource: self)
self.dataTable.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.dataTable.frame = self.view.frame
self.view.addSubview(self.dataTable);

self.addDataSourceAfter()
}
public func addDataSourceAfter(){

self.dataSource = [[
DataTableValueType.string("Pavan"),
DataTableValueType.string("Juice"),
DataTableValueType.string("Swift and Php"),
DataTableValueType.string("Be a game publisher"),
DataTableValueType.float(175.25)
],
[
DataTableValueType.string("NoelDavies"),
DataTableValueType.string("Water"),
DataTableValueType.string("Php and Javascript"),
DataTableValueType.string("'Be a fucking paratrooper machine'"),
DataTableValueType.float(185.80)
],
[
DataTableValueType.string("Redsaint"),
DataTableValueType.string("Cheerwine and Dr.Pepper"),
DataTableValueType.string("Java"),
DataTableValueType.string("'Creating an awesome RPG Game game'"),
DataTableValueType.float(185.42)
],
]

self.dataTable.reload()
}
}

extension DataTableWithDataSourceViewController: SwiftDataTableDataSource {
public func dataTable(_ dataTable: SwiftDataTable, headerTitleForColumnAt columnIndex: NSInteger) -> String {
return self.headerTitles[columnIndex]
}

public func numberOfColumns(in: SwiftDataTable) -> Int {
return 4
}

func numberOfRows(in: SwiftDataTable) -> Int {
return self.dataSource.count
}

public func dataTable(_ dataTable: SwiftDataTable, dataForRowAt index: NSInteger) -> [DataTableValueType] {
return self.dataSource[index]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

5 changes: 2 additions & 3 deletions Example/SwiftDataTables/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ class ViewController: UIViewController {

var options = DataTableConfiguration()
options.defaultOrdering = DataTableColumnOrder(index: 1, order: .ascending)



self.dataTable = SwiftDataTable(
data: self.data(),
headerTitles: self.columnHeaders(),
options: options
)
self.automaticallyAdjustsScrollViewInsets = false

self.dataTable.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 1)

//25/255, green: 33/255, blue: 39/255, alpha: 1)
Expand Down
Loading

0 comments on commit 9115efb

Please sign in to comment.