implemented estimatedRowHeight

This commit is contained in:
Max Sokolov 2015-11-15 13:44:05 +03:00
parent 6ee01134ff
commit c8333322cc
6 changed files with 28 additions and 26 deletions

View File

@ -146,8 +146,19 @@ extension TableDirector {
}
extension TableDirector {
// MARK: UITableViewDelegate - actions
public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return builderAtIndexPath(indexPath).0.estimatedRowHeight
}
public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return triggerAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension
}
public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
@ -174,15 +185,4 @@ extension TableDirector {
return triggerAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true
}
public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 300
}
public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
print(indexPath)
return triggerAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension
}
}

View File

@ -49,21 +49,21 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
private var items = [I]()
public var reusableIdentifier: String
public var estimatedRowHeight: Float
public var estimatedRowHeight: CGFloat
public var numberOfRows: Int {
get {
return items.count
}
}
public init(item: I, id: String, estimatedRowHeight: Float = 0) {
public init(item: I, id: String, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
reusableIdentifier = id
self.estimatedRowHeight = estimatedRowHeight
items.append(item)
}
public init(items: [I]? = nil, id: String, estimatedRowHeight: Float = 0) {
public init(items: [I]? = nil, id: String, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
reusableIdentifier = id
self.estimatedRowHeight = estimatedRowHeight
@ -121,11 +121,11 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
*/
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
public init(item: I, estimatedRowHeight: Float = 0) {
public init(item: I, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
super.init(item: item, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight)
}
public init(items: [I]? = nil, estimatedRowHeight: Float = 0) {
public init(items: [I]? = nil, estimatedRowHeight: CGFloat = UITableViewAutomaticDimension) {
super.init(items: items, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight)
}

View File

@ -112,7 +112,7 @@ public protocol RowBuilder {
var numberOfRows: Int { get }
var reusableIdentifier: String { get }
var estimatedRowHeight: Float { get }
var estimatedRowHeight: CGFloat { get }
func triggerAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject?
}

View File

@ -122,6 +122,7 @@
TargetAttributes = {
DAB7EB261BEF787300D2AD5E = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = Z48R734SJX;
};
};
};
@ -279,11 +280,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = TabletDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tablet.TabletDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
};
name = Debug;
};
@ -291,11 +295,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = TabletDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tablet.TabletDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
};
name = Release;
};

View File

@ -45,17 +45,12 @@ class ViewController: UIViewController {
return nil
}
.action(.configure) { (data) -> Void in
data.cell!.contentLabel.text = "With iOS 8, Apple has internalized much of the work that previously had to be implemented by you prior to iOS 8. In order to allow the self-sizing cell mechanism to work, you must first set the rowHeight property on the table view to the constant UITableViewAutomaticDimension. Then, you simply need to enable row height estimation by setting the table view's estimatedRowHeight property to a nonzero value, for example"
//data.cell!.setNeedsUpdateConstraints()
//data.cell!.updateConstraintsIfNeeded()
}
let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [configurableRowBuilder])
let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder])
tableDirector.appendSection(sectionBuilder)
}
}
// вход со стороны кутузовского проспекта между домами 10 14 левее чайхоны, на охране сказать кодовое слово Магия - найти клуб лабиринт
}