From 3f54cacab0d336f4125e528bf9c7f40d5a278c10 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Thu, 26 May 2016 01:42:55 +0300 Subject: [PATCH] estimated height improvements --- Tablet/RowBuilder.swift | 2 +- Tablet/TableBaseRowBuilder.swift | 2 +- Tablet/TableDirector.swift | 3 ++- Tablet/TablePrototypeRowBuilder.swift | 21 +--------------- Tablet/TableRowBuilder.swift | 2 +- Tablet/TableSectionBuilder.swift | 2 +- Tablet/Tablet.swift | 3 +-- Tablet/Tablet.xcodeproj/project.pbxproj | 4 ++-- .../Controllers/MainController.swift | 2 +- .../TabletDemo.xcodeproj/project.pbxproj | 24 ++++--------------- 10 files changed, 15 insertions(+), 50 deletions(-) diff --git a/Tablet/RowBuilder.swift b/Tablet/RowBuilder.swift index 0f2415d..02a7abc 100644 --- a/Tablet/RowBuilder.swift +++ b/Tablet/RowBuilder.swift @@ -31,7 +31,7 @@ public protocol RowBuilder { func willUpdateDirector(director: TableDirector?) func rowHeight(index: Int) -> CGFloat - func estimatedRowHeight() -> CGFloat + func estimatedRowHeight(index: Int) -> CGFloat func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? } \ No newline at end of file diff --git a/Tablet/TableBaseRowBuilder.swift b/Tablet/TableBaseRowBuilder.swift index d31f092..f365fc2 100644 --- a/Tablet/TableBaseRowBuilder.swift +++ b/Tablet/TableBaseRowBuilder.swift @@ -57,7 +57,7 @@ public class TableBaseRowBuilder CGFloat { + public func estimatedRowHeight(index: Int) -> CGFloat { return 44 } diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index b0574b5..6bc4d97 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -141,7 +141,8 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate // MARK: UITableViewDelegate - actions public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { - return builderAtIndexPath(indexPath).0.estimatedRowHeight() + let builder = builderAtIndexPath(indexPath) + return builder.0.estimatedRowHeight(builder.1) } public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { diff --git a/Tablet/TablePrototypeRowBuilder.swift b/Tablet/TablePrototypeRowBuilder.swift index b28cf68..f37d158 100644 --- a/Tablet/TablePrototypeRowBuilder.swift +++ b/Tablet/TablePrototypeRowBuilder.swift @@ -33,7 +33,7 @@ public class TablePrototypeRowBuilder CGFloat { + public override func estimatedRowHeight(index: Int) -> CGFloat { return UITableViewAutomaticDimension } @@ -74,25 +74,6 @@ public class TablePrototypeRowBuilder AnyObject? { if case .configure = action { diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index 210a3e8..222e0cc 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -41,7 +41,7 @@ public class TableRowBuilder CGFloat { + public override func estimatedRowHeight(index: Int) -> CGFloat { return CGFloat(CellType.estimatedHeight()) } } \ No newline at end of file diff --git a/Tablet/TableSectionBuilder.swift b/Tablet/TableSectionBuilder.swift index d9e300a..1797852 100644 --- a/Tablet/TableSectionBuilder.swift +++ b/Tablet/TableSectionBuilder.swift @@ -25,7 +25,7 @@ import UIKit Can host several row builders. */ public class TableSectionBuilder { - + weak var tableDirector: TableDirector? { didSet { guard let director = tableDirector else { return } diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index 8e5f0c2..bf5e653 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -110,5 +110,4 @@ public class Action { public func invoke() { NSNotificationCenter.defaultCenter().postNotificationName(TabletNotifications.CellAction, object: self, userInfo: userInfo) } -} - +} \ No newline at end of file diff --git a/Tablet/Tablet.xcodeproj/project.pbxproj b/Tablet/Tablet.xcodeproj/project.pbxproj index 77a0417..1317545 100644 --- a/Tablet/Tablet.xcodeproj/project.pbxproj +++ b/Tablet/Tablet.xcodeproj/project.pbxproj @@ -97,13 +97,13 @@ DAC2D68B1C9D7990009E9C19 /* Classes */ = { isa = PBXGroup; children = ( - DA08A04E1CF3AB0C00BBF1F8 /* ConfigurableCell.swift */, - DA08A0501CF3AB6100BBF1F8 /* RowBuilder.swift */, DAC2D68C1C9D799E009E9C19 /* TableDirector.swift */, + DA08A0501CF3AB6100BBF1F8 /* RowBuilder.swift */, DAC2D68D1C9D799E009E9C19 /* TableBaseRowBuilder.swift */, 5058386D1CF62B0700224C58 /* TableRowBuilder.swift */, 5058386F1CF62B1300224C58 /* TablePrototypeRowBuilder.swift */, DAC2D68E1C9D799E009E9C19 /* TableSectionBuilder.swift */, + DA08A04E1CF3AB0C00BBF1F8 /* ConfigurableCell.swift */, DAC2D68F1C9D799E009E9C19 /* Tablet.swift */, ); name = Classes; diff --git a/TabletDemo/Classes/Presentation/Controllers/MainController.swift b/TabletDemo/Classes/Presentation/Controllers/MainController.swift index 20c5328..1b47a81 100644 --- a/TabletDemo/Classes/Presentation/Controllers/MainController.swift +++ b/TabletDemo/Classes/Presentation/Controllers/MainController.swift @@ -21,7 +21,7 @@ class MainController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - let rows = TablePrototypeRowBuilder(items: ["1", "1", "1", "1"]) + let rows = TableRowBuilder(items: ["1", "1", "1", "1"]) .action(.click) { [unowned self] e in self.performSegueWithIdentifier("headerfooter", sender: nil) } diff --git a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj index 5b1d76e..e5a839f 100644 --- a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj +++ b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj @@ -7,9 +7,8 @@ objects = { /* Begin PBXBuildFile section */ - 5058386B1CF6189D00224C58 /* Tablet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5058386A1CF6189D00224C58 /* Tablet.framework */; }; - 5058386C1CF6189D00224C58 /* Tablet.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5058386A1CF6189D00224C58 /* Tablet.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; DA08A0531CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */; }; + DA539C941CF6610400368ACB /* Tablet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA539C931CF6610400368ACB /* Tablet.framework */; }; DAC2D5CA1C9D303E009E9C19 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC2D5C91C9D303E009E9C19 /* AppDelegate.swift */; }; DAC2D5CF1C9D30A7009E9C19 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAC2D5CD1C9D30A7009E9C19 /* Main.storyboard */; }; DAC2D5D01C9D30A7009E9C19 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAC2D5CE1C9D30A7009E9C19 /* LaunchScreen.storyboard */; }; @@ -19,23 +18,9 @@ DACB717A1CC2D89D00432BD3 /* HeaderFooterController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DACB71791CC2D89D00432BD3 /* HeaderFooterController.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXCopyFilesBuildPhase section */ - DA539C921CF50E9900368ACB /* Embed Frameworks */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - 5058386C1CF6189D00224C58 /* Tablet.framework in Embed Frameworks */, - ); - name = "Embed Frameworks"; - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ - 5058386A1CF6189D00224C58 /* Tablet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Tablet.framework; path = "/Users/max/Library/Developer/Xcode/DerivedData/Tablet-bomgsgklcxthxkeamvdbfmrhqnno/Build/Products/Debug-iphonesimulator/Tablet.framework"; sourceTree = ""; }; DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardImageTableViewCell.swift; sourceTree = ""; }; + DA539C931CF6610400368ACB /* Tablet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Tablet.framework; path = "../../../../../Library/Developer/Xcode/DerivedData/Tablet-hgommdyxtgxijceamltarpblrbwc/Build/Products/Debug-iphoneos/Tablet.framework"; sourceTree = ""; }; DAB7EB271BEF787300D2AD5E /* TabletDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TabletDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; DAC2D5C91C9D303E009E9C19 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DAC2D5CD1C9D30A7009E9C19 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; @@ -52,7 +37,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 5058386B1CF6189D00224C58 /* Tablet.framework in Frameworks */, + DA539C941CF6610400368ACB /* Tablet.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -62,6 +47,7 @@ DA539C871CF50B1800368ACB /* Frameworks */ = { isa = PBXGroup; children = ( + DA539C931CF6610400368ACB /* Tablet.framework */, ); name = Frameworks; sourceTree = ""; @@ -69,7 +55,6 @@ DAB7EB1E1BEF787300D2AD5E = { isa = PBXGroup; children = ( - 5058386A1CF6189D00224C58 /* Tablet.framework */, DAC2D5C61C9D2FE5009E9C19 /* Classes */, DAC2D5CB1C9D3058009E9C19 /* Resources */, DA539C871CF50B1800368ACB /* Frameworks */, @@ -166,7 +151,6 @@ DAB7EB231BEF787300D2AD5E /* Sources */, DAB7EB241BEF787300D2AD5E /* Frameworks */, DAB7EB251BEF787300D2AD5E /* Resources */, - DA539C921CF50E9900368ACB /* Embed Frameworks */, ); buildRules = ( );