diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index 92649ea..54c9853 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -56,16 +56,16 @@ public class TableRowBuilder : RowBuilder { } } - public init(item: I, id: String, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { + public init(item: I, id: String? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { - reusableIdentifier = id + reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "" self.estimatedRowHeight = estimatedRowHeight items.append(item) } - public init(items: [I]? = nil, id: String, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { + public init(items: [I]? = nil, id: String? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) { - reusableIdentifier = id + reusableIdentifier = id ?? NSStringFromClass(C).componentsSeparatedByString(".").last ?? "" self.estimatedRowHeight = estimatedRowHeight if items != nil { @@ -105,6 +105,10 @@ public class TableRowBuilder : RowBuilder { public func registerCell(inTableView tableView: UITableView) { + if tableView.dequeueReusableCellWithIdentifier(reusableIdentifier) != nil { + return + } + guard let resource = NSStringFromClass(C).componentsSeparatedByString(".").last else { return } let bundle = NSBundle(forClass: C.self) diff --git a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj index f241c66..765f0d8 100644 --- a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj +++ b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ DAB7EB351BEF787300D2AD5E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAB7EB331BEF787300D2AD5E /* LaunchScreen.storyboard */; }; DAB7EB3E1BEF78A400D2AD5E /* Tablet.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */; }; DAB7EB401BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */; }; + DAF003961C14DC0C0028C3D6 /* MyNibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */; }; + DAF003981C14DC250028C3D6 /* MyNibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -34,6 +36,8 @@ DAB7EB361BEF787300D2AD5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tablet.swift; sourceTree = ""; }; DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableTableViewCell.swift; sourceTree = ""; }; + DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyNibTableViewCell.swift; sourceTree = ""; }; + DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MyNibTableViewCell.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -71,6 +75,8 @@ DAB7EB2C1BEF787300D2AD5E /* ViewController.swift */, DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */, DA1BCD101BF7388C00CC0479 /* CustomTableActions.swift */, + DAF003951C14DC0C0028C3D6 /* MyNibTableViewCell.swift */, + DAF003971C14DC250028C3D6 /* MyNibTableViewCell.xib */, DAB7EB2E1BEF787300D2AD5E /* Main.storyboard */, DAB7EB311BEF787300D2AD5E /* Assets.xcassets */, DAB7EB331BEF787300D2AD5E /* LaunchScreen.storyboard */, @@ -150,6 +156,7 @@ buildActionMask = 2147483647; files = ( DAB7EB351BEF787300D2AD5E /* LaunchScreen.storyboard in Resources */, + DAF003981C14DC250028C3D6 /* MyNibTableViewCell.xib in Resources */, DAB7EB321BEF787300D2AD5E /* Assets.xcassets in Resources */, DAB7EB301BEF787300D2AD5E /* Main.storyboard in Resources */, ); @@ -165,6 +172,7 @@ 508B71841BF48DD300272920 /* TableSectionBuilder.swift in Sources */, DAB7EB2D1BEF787300D2AD5E /* ViewController.swift in Sources */, DAB7EB3E1BEF78A400D2AD5E /* Tablet.swift in Sources */, + DAF003961C14DC0C0028C3D6 /* MyNibTableViewCell.swift in Sources */, 508B71861BF48E0D00272920 /* TableRowBuilder.swift in Sources */, DA1BCD0F1BF5472C00CC0479 /* TableDirector.swift in Sources */, DAB7EB401BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift in Sources */, diff --git a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 5bee61d..0324db2 100644 Binary files a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TabletDemo/TabletDemo/MyNibTableViewCell.swift b/TabletDemo/TabletDemo/MyNibTableViewCell.swift new file mode 100644 index 0000000..4888fb9 --- /dev/null +++ b/TabletDemo/TabletDemo/MyNibTableViewCell.swift @@ -0,0 +1,15 @@ +// +// MyNibTableViewCell.swift +// TabletDemo +// +// Created by Max Sokolov on 07/12/15. +// Copyright © 2015 Tablet. All rights reserved. +// + +import Foundation +import UIKit + +class MyNibTableViewCell : UITableViewCell { + + +} \ No newline at end of file diff --git a/TabletDemo/TabletDemo/MyNibTableViewCell.xib b/TabletDemo/TabletDemo/MyNibTableViewCell.xib new file mode 100644 index 0000000..02401db --- /dev/null +++ b/TabletDemo/TabletDemo/MyNibTableViewCell.xib @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TabletDemo/TabletDemo/ViewController.swift b/TabletDemo/TabletDemo/ViewController.swift index 9d996c0..0a7a835 100644 --- a/TabletDemo/TabletDemo/ViewController.swift +++ b/TabletDemo/TabletDemo/ViewController.swift @@ -52,13 +52,11 @@ class ViewController: UIViewController { data.cell!.contentLabel.text = "Tablet is a super lightweight yet powerful generic library that handles a complexity of UITableView's datasource and delegate methods in a Swift environment. Tablet's goal is to provide an easiest way to create complex table views. With Tablet you don't have to write a messy code of switch or if statements when you deal with bunch of different cells in different sections." } - - let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder]) - - tableDirector += sectionBuilder + + sectionBuilder.appendRowBuilder(TableRowBuilder(item: 0)) } } \ No newline at end of file