JomloTableView 0.2.1

JomloTableView 0.2.1

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布2017年4月
SwiftSwift 版本3.0
SPM支持 SPM

Seto Elkahfi维护。



JomloTableView

一个具有可分离部分和行的 iOS UITableView。可以使用单个部分和多个行,或者多个部分和多个行。在每个视图控制器中遵守 UITableViewDelegate 和 UITableViewDataSource 是一项普通且重复的任务。直接将委托和数据源移到表格视图,并为表格提供部分(s)和行(s)。从庞大的视图中解放出来。

参考:https://goo.gl/zTGfpihttps://goo.gl/7vMbSF

示例

要运行示例项目,请克隆仓库,然后先从 Example 目录中运行 pod install

git clone https://github.com/setoelkahfi/JomloTableView
cd Example
pod install

需求

iOS 8

安装

JomloTableView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "JomloTableView"

用法

简单用法

使用单个部分和多个行。以下所有行都来自单个类。

import UIKit
import JomloTableView

// Another code

    @IBOutlet var jomloTableView: JomloTableView!

    var exampleSection = JomloTableViewSection()

    override func viewDidLoad() {
        super.viewDidLoad()

        let row0 = SimpleRow("Simple table view", subTitle: "A simple table view like we usually use. But this time, we use JomloTableView.")
        row0.setOnRowClicked { (row) in
            self.performSegue(withIdentifier: "showSimpleTableViewExample", sender: self)
        }
        exampleSection.addRow(row: row0)

        let row1 = SimpleRow("Load more", subTitle: "A JomloTableView with load more row at the bottom. Will load infinite row if we scroll the table view to the bottom.")
        row1.setOnRowClicked { (row) in
            self.performSegue(withIdentifier: "showLoadMoreExample", sender: self)
        }
        exampleSection.addRow(row: row1)

        // Another rows to add

        jomloTableView.addSection(section: exampleSection)
        jomloTableView.reloadData()

    }

// Another code

import UIKit
import JomloTableView

class SimpleCell: JomloTableViewCell {

    @IBOutlet var titleLabel: UILabel!
    @IBOutlet var subTitleLabel: UILabel!

}

class SimpleRow: JomloTableViewRow {

    var title: String!
    var subTitle: String!

    init(_ title: String, subTitle: String) {
        self.title = title
        self.subTitle = subTitle
    }

    override var identifier: String {
        return "SimpleCell"
    }

    override var rowHeight: CGFloat {
        return UITableViewAutomaticDimension
    }

    override var estimatedRowHeight: CGFloat {
        return 64
    }

    override func populateView(cell: JomloTableViewCell) {
        let cell = cell as! SimpleCell
        cell.titleLabel.text = title
        cell.subTitleLabel.text = subTitle
    }
}

   

加载更多行

此表格视图在加载更多行时将加载更多行。如果用户滚动到表格视图的底部,此示例将加载无限行。每次加载八行。

import UIKit
import JomloTableView

// Another code

    @IBOutlet var jomloTableView: JomloTableView!

    let tableSection = JomloTableViewSection()

    override func viewDidLoad() {
        super.viewDidLoad()

        jomloTableView.addSection(section: tableSection)
        addRows()
    }

    func addRows() {
        for _ in 0..<8 {
            let rowNumber = tableSection.count + 1
            let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.")
            tableSection.addRow(row: row)
        }

        addLoadMoreRow()
    }

    func addLoadMoreRow() {

        let loadMoreRow = LoadMoreRow {
            // To get the effect or loading, delay the execution after 3 seconds
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: {
                self.tableSection.removeLastRow()
                self.addRows()
            })
        }

        tableSection.addRow(row: loadMoreRow)
        jomloTableView.reloadData()
    }

// Another code

      

作者

Seto Elkahfi, [email protected]

许可协议

JomloTableView 在 MIT 许可协议下提供。更多信息请参阅 LICENSE 文件。