test register nib

This commit is contained in:
Max Sokolov 2015-11-29 23:37:16 +03:00
parent 19ae34f2f0
commit 835feb0905
4 changed files with 23 additions and 1 deletions

View File

@ -73,6 +73,20 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1)
}
}
func registerNibs() {
let bundle = NSBundle(forClass: UITableViewCell.self)
if let _ = bundle.pathForResource("cell name", ofType: "nib") { // existing cell
tableView.registerNib(UINib(nibName: "", bundle: bundle), forCellReuseIdentifier: "")
} else {
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "")
}
}
}
extension TableDirector {

View File

@ -141,4 +141,10 @@ public extension TableRowBuilder {
items.removeAll()
}
}
public func +=<T, C where C : UITableViewCell>(var left: TableRowBuilder<T, C>, right: T) -> TableRowBuilder<T, C> {
left.appendItems([right])
return left
}

View File

@ -18,7 +18,7 @@ class ViewController: UIViewController {
tableDirector = TableDirector(tableView: tableView)
let rowBuilder = TableRowBuilder<Int, UITableViewCell>(items: [1, 2, 3, 4], id: "cell")
var rowBuilder = TableRowBuilder<Int, UITableViewCell>(items: [1, 2, 3, 4], id: "cell")
.action(.configure) { data in
data.cell?.textLabel?.text = "\(data.item)"
@ -52,6 +52,8 @@ class ViewController: UIViewController {
data.cell!.contentLabel.text = "Tablet is a super lightweight yet powerful generic library that handles a complexity of UITableView's datasource and delegate methods in a Swift environment. Tablet's goal is to provide an easiest way to create complex table views. With Tablet you don't have to write a messy code of switch or if statements when you deal with bunch of different cells in different sections."
}
//rowBuilder += rowBuilder
let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder])