Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
8f895bdd31 | |
|
|
79aef4dd39 | |
|
|
b1f3b110b1 | |
|
|
b5f7bd25e6 |
|
|
@ -1,6 +1,6 @@
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'Tablet'
|
s.name = 'Tablet'
|
||||||
s.version = '0.2.6'
|
s.version = '0.2.8'
|
||||||
|
|
||||||
s.homepage = 'https://github.com/maxsokolov/tablet'
|
s.homepage = 'https://github.com/maxsokolov/tablet'
|
||||||
s.summary = 'Powerful type-safe tool for UITableView. Swift 2.0 is required.'
|
s.summary = 'Powerful type-safe tool for UITableView. Swift 2.0 is required.'
|
||||||
|
|
@ -12,5 +12,5 @@ Pod::Spec.new do |s|
|
||||||
|
|
||||||
s.source_files = 'Tablet/*.swift'
|
s.source_files = 'Tablet/*.swift'
|
||||||
s.module_name = 'Tablet'
|
s.module_name = 'Tablet'
|
||||||
s.source = { :git => 'https://github.com/maxsokolov/tablet.git', :tag => s.version }
|
s.source = { :git => 'https://github.com/maxsokolov/Tablet.swift.git', :tag => s.version }
|
||||||
end
|
end
|
||||||
|
|
@ -37,7 +37,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
||||||
self.tableView.delegate = self
|
self.tableView.delegate = self
|
||||||
self.tableView.dataSource = self
|
self.tableView.dataSource = self
|
||||||
|
|
||||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didReceiveAction:", name: kActionPerformedNotificationKey, object: nil)
|
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(didReceiveAction), name: kActionPerformedNotificationKey, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|
@ -217,6 +217,20 @@ public extension TableDirector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public extension TableDirector {
|
||||||
|
|
||||||
|
public func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
||||||
|
return invokeAction(.canEdit, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? false
|
||||||
|
}
|
||||||
|
|
||||||
|
public func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
|
||||||
|
|
||||||
|
if editingStyle == .Delete {
|
||||||
|
invokeAction(.clickDelete, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func +=(left: TableDirector, right: RowBuilder) {
|
public func +=(left: TableDirector, right: RowBuilder) {
|
||||||
|
|
||||||
left.appendSection(TableSectionBuilder(rowBuilders: [right]))
|
left.appendSection(TableSectionBuilder(rowBuilders: [right]))
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,11 @@ internal enum ActionHandler<I, C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Responsible for building cells of given type and passing items to them.
|
Responsible for building cells of given type and passing items to them.
|
||||||
*/
|
*/
|
||||||
public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
|
public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
|
||||||
|
|
||||||
private var actions = Dictionary<String, ActionHandler<I, C>>()
|
private var actions = Dictionary<String, ActionHandler<I, C>>()
|
||||||
private var items = [I]()
|
public var items = [I]()
|
||||||
|
|
||||||
public var reusableIdentifier: String
|
public var reusableIdentifier: String
|
||||||
public var estimatedRowHeight: CGFloat
|
public var estimatedRowHeight: CGFloat
|
||||||
|
|
@ -126,7 +126,7 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Responsible for building configurable cells of given type and passing items to them.
|
Responsible for building configurable cells of given type and passing items to them.
|
||||||
*/
|
*/
|
||||||
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
|
public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item == I, C: UITableViewCell> : TableRowBuilder<I, C> {
|
||||||
|
|
||||||
public init(item: I, estimatedRowHeight: CGFloat = 48) {
|
public init(item: I, estimatedRowHeight: CGFloat = 48) {
|
||||||
|
|
@ -152,6 +152,13 @@ public extension TableRowBuilder {
|
||||||
|
|
||||||
// MARK: Items manipulation
|
// MARK: Items manipulation
|
||||||
|
|
||||||
|
public func removeItemAtIndex(index: Int) {
|
||||||
|
|
||||||
|
if index < items.count {
|
||||||
|
items.removeAtIndex(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func appendItems(items: [I]) {
|
public func appendItems(items: [I]) {
|
||||||
|
|
||||||
self.items.appendContentsOf(items)
|
self.items.appendContentsOf(items)
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,14 @@ public class TableSectionBuilder {
|
||||||
|
|
||||||
internal extension TableSectionBuilder {
|
internal extension TableSectionBuilder {
|
||||||
|
|
||||||
internal func builderAtIndex(var index: Int) -> (RowBuilder, Int)? {
|
internal func builderAtIndex(index: Int) -> (RowBuilder, Int)? {
|
||||||
|
|
||||||
|
var builderIndex = index
|
||||||
for builder in builders {
|
for builder in builders {
|
||||||
if index < builder.numberOfRows {
|
if builderIndex < builder.numberOfRows {
|
||||||
return (builder, index)
|
return (builder, builderIndex)
|
||||||
}
|
}
|
||||||
index -= builder.numberOfRows
|
builderIndex -= builder.numberOfRows
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ internal let kActionPerformedNotificationKey = "_action"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The actions that Tablet provides.
|
The actions that Tablet provides.
|
||||||
*/
|
*/
|
||||||
public enum ActionType {
|
public enum ActionType {
|
||||||
|
|
||||||
case click
|
case click
|
||||||
|
|
@ -36,6 +36,8 @@ public enum ActionType {
|
||||||
case willDisplay
|
case willDisplay
|
||||||
case shouldHighlight
|
case shouldHighlight
|
||||||
case height
|
case height
|
||||||
|
case canEdit
|
||||||
|
case clickDelete
|
||||||
case custom(String)
|
case custom(String)
|
||||||
|
|
||||||
var key: String {
|
var key: String {
|
||||||
|
|
@ -68,7 +70,7 @@ public class ActionData<I, C> {
|
||||||
/**
|
/**
|
||||||
A custom action that you can trigger from your cell.
|
A custom action that you can trigger from your cell.
|
||||||
You can eacily catch actions using a chaining manner with your row builder.
|
You can eacily catch actions using a chaining manner with your row builder.
|
||||||
*/
|
*/
|
||||||
public class Action {
|
public class Action {
|
||||||
|
|
||||||
/// The cell that triggers an action.
|
/// The cell that triggers an action.
|
||||||
|
|
@ -96,10 +98,10 @@ public class Action {
|
||||||
/**
|
/**
|
||||||
If you want to delegate your cell configuration logic to cell itself (with your view model or even model) than
|
If you want to delegate your cell configuration logic to cell itself (with your view model or even model) than
|
||||||
just provide an implementation of this protocol for your cell. Enjoy safe-typisation.
|
just provide an implementation of this protocol for your cell. Enjoy safe-typisation.
|
||||||
*/
|
*/
|
||||||
public protocol ConfigurableCell {
|
public protocol ConfigurableCell {
|
||||||
|
|
||||||
typealias Item
|
associatedtype Item
|
||||||
|
|
||||||
static func reusableIdentifier() -> String
|
static func reusableIdentifier() -> String
|
||||||
func configureWithItem(item: Item)
|
func configureWithItem(item: Item)
|
||||||
|
|
@ -116,13 +118,15 @@ public extension ConfigurableCell where Self: UITableViewCell {
|
||||||
/**
|
/**
|
||||||
A protocol that every row builder should follow.
|
A protocol that every row builder should follow.
|
||||||
A certain section can only works with row builders that respect this protocol.
|
A certain section can only works with row builders that respect this protocol.
|
||||||
*/
|
*/
|
||||||
public protocol RowBuilder {
|
public protocol RowBuilder {
|
||||||
|
|
||||||
var numberOfRows: Int { get }
|
var numberOfRows: Int { get }
|
||||||
var reusableIdentifier: String { get }
|
var reusableIdentifier: String { get }
|
||||||
var estimatedRowHeight: CGFloat { get }
|
var estimatedRowHeight: CGFloat { get }
|
||||||
|
|
||||||
|
func removeItemAtIndex(index: Int)
|
||||||
|
|
||||||
func registerCell(inTableView tableView: UITableView)
|
func registerCell(inTableView tableView: UITableView)
|
||||||
func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject?
|
func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject?
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
Reference in New Issue