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]))
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ internal enum ActionHandler<I, C> {
|
||||||
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
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
@ -99,7 +101,7 @@ public class Action {
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
|
|
@ -123,6 +125,8 @@ public protocol RowBuilder {
|
||||||
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