From 92ee2b731c2c7e4c32885ff6bf6e68904a61540e Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Wed, 25 May 2016 01:31:22 +0300 Subject: [PATCH] fix autolayout issues --- Tablet/RowBuilder.swift | 3 +- Tablet/TableDirector.swift | 3 +- Tablet/TableRowBuilder.swift | 38 ++++++++++----- .../Controllers/MainController.swift | 2 +- .../Views/StoryboardImageTableViewCell.swift | 37 ++++++++++++++ TabletDemo/Resources/Info.plist | 2 + .../Storyboards/LaunchScreen.storyboard | 4 +- .../Resources/Storyboards/Main.storyboard | 48 ++++++++++++++++++- .../TabletDemo.xcodeproj/project.pbxproj | 16 ++++++- 9 files changed, 131 insertions(+), 22 deletions(-) create mode 100644 TabletDemo/Classes/Presentation/Views/StoryboardImageTableViewCell.swift diff --git a/Tablet/RowBuilder.swift b/Tablet/RowBuilder.swift index ced4fb6..0f2415d 100644 --- a/Tablet/RowBuilder.swift +++ b/Tablet/RowBuilder.swift @@ -27,10 +27,11 @@ public protocol RowBuilder { var reusableIdentifier: String { get } var numberOfRows: Int { get } - var estimatedRowHeight: CGFloat { get } func willUpdateDirector(director: TableDirector?) func rowHeight(index: Int) -> CGFloat + func estimatedRowHeight() -> 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/TableDirector.swift b/Tablet/TableDirector.swift index 0ce4c13..b0574b5 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -141,11 +141,10 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate // MARK: UITableViewDelegate - actions public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { - return builderAtIndexPath(indexPath).0.estimatedRowHeight + return builderAtIndexPath(indexPath).0.estimatedRowHeight() } public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { - let builder = builderAtIndexPath(indexPath) return builder.0.rowHeight(builder.1) } diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index e1cb19e..1cf6335 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -37,11 +37,7 @@ public class TableBaseRowBuilder CGFloat { + return 44 + } + // MARK: - Chaining actions - public func action(key: String, handler: (data: ActionData) -> Void) -> Self { @@ -127,10 +127,6 @@ public class TableBaseRowBuilder : TableBaseRowBuilder { - public override var estimatedRowHeight: CGFloat { - return CGFloat(CellType.estimatedHeight()) - } - public init(item: DataType) { super.init(item: item, id: CellType.reusableIdentifier()) } @@ -146,13 +142,17 @@ public class TableRowBuilder CGFloat { + return CGFloat(CellType.estimatedHeight()) + } } public class TablePrototypeRowBuilder : TableBaseRowBuilder { private var cachedHeights = [Int: CGFloat]() private var prototypeCell: CellType? - + public init(item: DataType) { super.init(item: item, id: CellType.reusableIdentifier()) } @@ -160,6 +160,10 @@ public class TablePrototypeRowBuilder CGFloat { + return UITableViewAutomaticDimension + } public override func rowHeight(index: Int) -> CGFloat { @@ -168,17 +172,25 @@ public class TablePrototypeRowBuilder(items: ["1"]) + let rows = TablePrototypeRowBuilder(items: ["1", "1", "1", "1"]) .action(.click) { [unowned self] e in self.performSegueWithIdentifier("headerfooter", sender: nil) } diff --git a/TabletDemo/Classes/Presentation/Views/StoryboardImageTableViewCell.swift b/TabletDemo/Classes/Presentation/Views/StoryboardImageTableViewCell.swift new file mode 100644 index 0000000..5a848f6 --- /dev/null +++ b/TabletDemo/Classes/Presentation/Views/StoryboardImageTableViewCell.swift @@ -0,0 +1,37 @@ +// +// StoryboardImageTableViewCell.swift +// TabletDemo +// +// Created by Max Sokolov on 24/05/16. +// Copyright © 2016 Tablet. All rights reserved. +// + +import UIKit +import Tablet + +class StoryboardImageTableViewCell: UITableViewCell, ConfigurableCell { + + typealias T = String + + @IBOutlet var titleLabel: UILabel! + @IBOutlet var subtitleLabel: UILabel! + @IBOutlet var customImageView: UIImageView! + + func configure(string: T) { + + titleLabel.text = "Test" + subtitleLabel.text = "Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.Copyright © 2016 Tablet. All rights reserved.1" + } + + static func estimatedHeight() -> Float { + return 140 + } + + override func layoutSubviews() { + super.layoutSubviews() + + //contentView.layoutIfNeeded() + + subtitleLabel.preferredMaxLayoutWidth = subtitleLabel.bounds.size.width + } +} \ No newline at end of file diff --git a/TabletDemo/Resources/Info.plist b/TabletDemo/Resources/Info.plist index 6c48029..6905cc6 100644 --- a/TabletDemo/Resources/Info.plist +++ b/TabletDemo/Resources/Info.plist @@ -33,6 +33,8 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight diff --git a/TabletDemo/Resources/Storyboards/LaunchScreen.storyboard b/TabletDemo/Resources/Storyboards/LaunchScreen.storyboard index c9b7564..0a546bb 100644 --- a/TabletDemo/Resources/Storyboards/LaunchScreen.storyboard +++ b/TabletDemo/Resources/Storyboards/LaunchScreen.storyboard @@ -1,8 +1,8 @@ - + - + diff --git a/TabletDemo/Resources/Storyboards/Main.storyboard b/TabletDemo/Resources/Storyboards/Main.storyboard index 1a1d1c2..4edf1ae 100644 --- a/TabletDemo/Resources/Storyboards/Main.storyboard +++ b/TabletDemo/Resources/Storyboards/Main.storyboard @@ -39,8 +39,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj index 9779299..f3e4618 100644 --- a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj +++ b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + DA08A0531CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */; }; 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 */; }; @@ -17,6 +18,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardImageTableViewCell.swift; 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 = ""; }; @@ -39,11 +41,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + DA539C871CF50B1800368ACB /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; DAB7EB1E1BEF787300D2AD5E = { isa = PBXGroup; children = ( DAC2D5C61C9D2FE5009E9C19 /* Classes */, DAC2D5CB1C9D3058009E9C19 /* Resources */, + DA539C871CF50B1800368ACB /* Frameworks */, DAB7EB281BEF787300D2AD5E /* Products */, ); sourceTree = ""; @@ -122,6 +132,7 @@ isa = PBXGroup; children = ( DACB71771CC2D6ED00432BD3 /* StoryboardTableViewCell.swift */, + DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */, ); path = Views; sourceTree = ""; @@ -202,6 +213,7 @@ DACB71761CC2D63D00432BD3 /* MainController.swift in Sources */, DAC2D5CA1C9D303E009E9C19 /* AppDelegate.swift in Sources */, DACB717A1CC2D89D00432BD3 /* HeaderFooterController.swift in Sources */, + DA08A0531CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -298,7 +310,7 @@ INFOPLIST_FILE = Resources/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.tablet.tablet; + PRODUCT_BUNDLE_IDENTIFIER = com.tablet.demo; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; }; @@ -313,7 +325,7 @@ INFOPLIST_FILE = Resources/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.tablet.tablet; + PRODUCT_BUNDLE_IDENTIFIER = com.tablet.demo; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; };