Skip to content

Repository files navigation

TableViewContent

VersionLicensePlatform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

TableViewContent is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod'TableViewContent'

Usage

You can declare table view sections and cells as follows:

Section{DefaultRow(title:"title")DefaultRow(title:"title", style:.subtitle).detailText("subtitle")DefaultRow(title:"title", style:.value1).detailText("value1")DefaultRow(title:"title", style:.value2).accessoryType(.disclosureIndicator).detailText("value2")}

To handle cell selection, call didSelect method.

DefaultRow(title:"title", style:.value2).accessoryType(.disclosureIndicator).detailText("value2").didSelect{ _, _, _ inletviewController=UIStoryboard(name:"Main", bundle:nil).instantiateViewController(withIdentifier:"ViewController")self.navigationController?.pushViewController(viewController, animated:true)}

Define class that inherit Row<T: UITableViewCell> for implementing custom row.

classCustomTableViewCell:UITableViewCell{publictypealiasAction=()->Void@IBOutletprivatevarbutton:UIButton!varbuttonPressedAction:Action={}overridefunc awakeFromNib(){
super.awakeFromNib()
button.addTarget(self, action: #selector(buttonPressed(_:)), for:.touchUpInside)}@objcprivatefunc buttonPressed(_:UIButton){buttonPressedAction()}}classCustomRow:Row<CustomTableViewCell>{publictypealiasAction=()->VoidprivatevarbuttonPressedAction:Action={}init(){
super.init(.nib(.init(nibName:"CustomTableViewCell", bundle:nil)),
reuseIdentifier:NSStringFromClass(CustomTableViewCell.self))selectionStyle(.none)}overridefunc defaultCellConfiguration(_ cell:CustomTableViewCell, _ indexPath:IndexPath){
cell.buttonPressedAction = buttonPressedAction
}convenienceinit(_ action:@escapingAction){self.init()
buttonPressedAction = action
}@discardableResultfunc didButtonPress(_ action:@escapingAction)->Self{
buttonPressedAction = action
returnself}@objcprivatefunc buttonPressed(){buttonPressedAction()}}

See example code to lean advanced usage.

Author

Akira Matsuda, akira.matsuda@me.com

License

TableViewContent is available under the MIT license. See the LICENSE file for more info.

About

Declare tableView row and section header/footer easy way.

Resources

Stars

22 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages