Git Product home page Git Product logo

setoelkahfi / jomlotableview Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 36.29 MB

An iOS UITableView with detachable section and row. Use single section with multiple rows, or multiple sections with multiple rows.

Home Page: https://swiftpackageindex.com/setoelkahfi/JomloTableView

License: MIT License

Swift 92.17% Ruby 7.83%
uitableview uitableviewdatasource uitableviewdelegate swift objective-c ios uitableviewcell swift-library swift-3 uitableview-subclass

jomlotableview's Introduction

JomloTableView

Version License Platform

An iOS UITableView with detachable section and row. Use single section with multiple rows, or multiple sections with multiple rows. Conforming UITableViewDelegate and UITableViewDataSource in every view controller is a mundane and repetitive task. Move the delegate and the data source directly to the table view, and supply the table with section(s) and row(s). Free yourself from Massive-View-Controller.

Reference: https://goo.gl/zTGfpi, https://goo.gl/7vMbSF

Example

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

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

Requirements

iOS 8

Installation

JomloTableView is available through CocoaPods and Swift Package Manager.

Cocoapods

To install it, simply add the following line to your Podfile:

pod "JomloTableView"

Swift Package Manager

Usage

Simple usage

Use single section with multiple rows. All the rows below are from single class.

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

The row

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
    }
}

   

Load more row

This table view will load more row if loadMoreRow is populated. This example will load infinite rows if user scroll to bottom of table view. Eight rows per each load.

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

      

Author

Seto Elkahfi, [email protected]

License

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

jomlotableview's People

Contributors

setoelkahfi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.