some more code
This commit is contained in:
parent
d5ed53a0b6
commit
8104b26dbb
|
|
@ -7,6 +7,8 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */; };
|
||||
78011A691D47AF5100EA16A2 /* CellCreationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A681D47AF5100EA16A2 /* CellCreationType.swift */; };
|
||||
7824CA521CFEE6B700D7B132 /* UIImage+RenderTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */; };
|
||||
7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */; };
|
||||
785C33451CFC908800C4C4AA /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785C33441CFC908800C4C4AA /* TableViewController.swift */; };
|
||||
|
|
@ -49,6 +51,8 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+DefaultReuseIdentifier.swift"; sourceTree = "<group>"; };
|
||||
78011A681D47AF5100EA16A2 /* CellCreationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellCreationType.swift; sourceTree = "<group>"; };
|
||||
7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+RenderTemplate.swift"; sourceTree = "<group>"; };
|
||||
7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EstimatedViewHeightProtocol.swift; sourceTree = "<group>"; };
|
||||
785C33441CFC908800C4C4AA /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -103,6 +107,14 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
78011A651D47AF3000EA16A2 /* Enums */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
78011A681D47AF5100EA16A2 /* CellCreationType.swift */,
|
||||
);
|
||||
path = Enums;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7830C4131C6B336A00180D02 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -180,6 +192,7 @@
|
|||
7830C4131C6B336A00180D02 /* Frameworks */,
|
||||
78A74EAA1C6B401800FE9724 /* Classes */,
|
||||
78CFEE441C5C45E500F50370 /* Extensions */,
|
||||
78011A651D47AF3000EA16A2 /* Enums */,
|
||||
78CFEE491C5C45E500F50370 /* Protocols */,
|
||||
78CFEE2D1C5C456B00F50370 /* LeadKit.h */,
|
||||
78CFEE2F1C5C456B00F50370 /* Info.plist */,
|
||||
|
|
@ -249,6 +262,7 @@
|
|||
children = (
|
||||
78CFEE481C5C45E500F50370 /* UIView+LoadFromNib.swift */,
|
||||
78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */,
|
||||
78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */,
|
||||
);
|
||||
path = UIView;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -427,6 +441,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
78011A691D47AF5100EA16A2 /* CellCreationType.swift in Sources */,
|
||||
785C33451CFC908800C4C4AA /* TableViewController.swift in Sources */,
|
||||
7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */,
|
||||
78CFEE541C5C45E500F50370 /* UIView+LoadFromNib.swift in Sources */,
|
||||
|
|
@ -435,6 +450,7 @@
|
|||
78CFEE571C5C45E500F50370 /* StaticNibNameProtocol.swift in Sources */,
|
||||
788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */,
|
||||
787783671CA04D4A001CDC9B /* NSString+SizeCalculation.swift in Sources */,
|
||||
78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */,
|
||||
78CFEE531C5C45E500F50370 /* UITableView+DequeueCustomCell.swift in Sources */,
|
||||
78E59B1B1C77470A00C6BFE9 /* ViewsGenerator.swift in Sources */,
|
||||
78B0FC811C6B2CD500358B64 /* App.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ public class ViewsGenerator<T where T: UIView>: ObjectsGenerator<T> {
|
|||
- returns: nothing
|
||||
*/
|
||||
init(poolSize: UInt, nibName: String) {
|
||||
super.init(poolSize: poolSize, objectsContructor: {() -> T in
|
||||
T.loadFromNib(named: nibName)
|
||||
})
|
||||
super.init(poolSize: poolSize, objectsContructor: { T.loadFromNib(named: nibName) })
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,7 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
public enum CellCreationType: Int {
|
||||
|
||||
case Preloaded = 0
|
||||
case OnTheFlight = 1
|
||||
|
||||
}
|
||||
|
||||
public class TableViewController: UITableViewController, CellsControllerProtocol {
|
||||
public class TableViewController<ContentType>: UITableViewController, CellsControllerProtocol {
|
||||
|
||||
private var heightCache: [NSIndexPath: CGFloat] = [:]
|
||||
|
||||
|
|
@ -50,6 +43,12 @@ public class TableViewController: UITableViewController, CellsControllerProtocol
|
|||
aCoder.encodeInteger(cellCreationType.rawValue, forKey: "CellCreationType")
|
||||
}
|
||||
|
||||
/**
|
||||
method which adds cells generator for cells with specified reuse identifier
|
||||
|
||||
- parameter cellsGenerator: cells generator
|
||||
- parameter cellIdentifier: cell reuse identifier
|
||||
*/
|
||||
public func registerCellsGenerator(cellsGenerator: ViewsGenerator<UITableViewCell>,
|
||||
forCellsWithIdentifier cellIdentifier: String) {
|
||||
cellsObjectsCreators[cellIdentifier] = cellsGenerator
|
||||
|
|
@ -97,20 +96,43 @@ public class TableViewController: UITableViewController, CellsControllerProtocol
|
|||
|
||||
// MARK: - Cache
|
||||
|
||||
/**
|
||||
method which invalidates cache
|
||||
*/
|
||||
public func invalidateCache() {
|
||||
heightCache = [:]
|
||||
}
|
||||
|
||||
// MARK: - Cells сontroller stub implementation
|
||||
|
||||
/**
|
||||
method which returns reuse identifier for cell at specified index path
|
||||
|
||||
- parameter indexPath: NSIndexPath object
|
||||
|
||||
- returns: reuse identifier
|
||||
*/
|
||||
public func cellIdentifierForIndexPath(indexPath: NSIndexPath) -> String {
|
||||
fatalError("Your should implement cellIdentifierForIndexPath(_:)")
|
||||
}
|
||||
|
||||
/**
|
||||
method which configures cell before it can be used
|
||||
|
||||
- parameter cell: UITableView or subclass cell
|
||||
- parameter atIndexPath: index path of cell
|
||||
*/
|
||||
public func configureCell(cell: UITableViewCell, atIndexPath: NSIndexPath) {
|
||||
// intended to be implemented in subclasses
|
||||
}
|
||||
|
||||
/**
|
||||
method which return height for cell at specified index path
|
||||
|
||||
- parameter indexPath: NSIndexPath object
|
||||
|
||||
- returns: height of cell at specified index path
|
||||
*/
|
||||
public func heightForCellAtIndexPath(indexPath: NSIndexPath) -> CGFloat {
|
||||
// intended to be implemented in subclasses
|
||||
return UITableViewAutomaticDimension
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// CellCreationType.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 26/07/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
enum which describes cell creation behaviour of CellsControllerProtocol
|
||||
|
||||
- Preloaded: cells is generated in advance
|
||||
- OnTheFlight: cells is created on demand
|
||||
*/
|
||||
public enum CellCreationType: Int {
|
||||
|
||||
case Preloaded = 0
|
||||
case OnTheFlight = 1
|
||||
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ extension UIView: StaticNibNameProtocol {
|
|||
*/
|
||||
|
||||
public class func nibName() -> String {
|
||||
return NSStringFromClass(self).componentsSeparatedByString(".").last!
|
||||
return String(self.dynamicType).componentsSeparatedByString(".").last!
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// UIView+DefaultReuseIdentifier.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 26/07/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIView: ReuseIdentifierProtocol {
|
||||
|
||||
/**
|
||||
default implementation of ReuseIdentifierProtocol
|
||||
|
||||
- returns: type name string
|
||||
*/
|
||||
public class func reuseIdentifier() -> String {
|
||||
return String(self.dynamicType)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue