Giter Site home page Giter Site logo

jake's Introduction

Jake

CI Status Version SPM License Platform

Contents

Demo

P547c.gif

Requirements

  • iOS 11.0+
  • Xcode 11+
  • Swift 5.3+

Installation

Cocoapods

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

pod 'Jake'

Swift Package Manager

  1. File > Swift Packages > Add Package Dependency
  2. Add https://github.com/Retro-Cartoons/Jake.git

OR

Update dependencies in Package.swift

dependencies: [
    .package(url: "https://github.com/Retro-Cartoons/Jake.git", .upToNextMajor(from: "1.0.0"))
]

Usage

JakeTableView Properties

var delegate: JakeTableViewDelegateAndDatasourceProtocol?
var hasSeparator: Bool = true // Set's separators is removed behind cells. When is set false removes separators.
var autoCollapse: Bool = true // When selected section expand other sections collapse automatically.

JakeTableViewHeader Properties & Functions

public var delegate: JakeTableViewHeaderProtocol?
public var section: Int?

public func expandedSection(_ section: Int) // When you want to use the autocollapse feature, it shows which header is expanded into the header.
public func collapseOrExpandTrigger() // It allows you to collapse and expand operations in the header.

XIB

StoryboardImplementation

Programmatically

private lazy var jakeTableView: JakeTableView = {
  let tableView = JakeTableView()
  tableView.translatesAutoresizingMaskIntoConstraints = false
  tableView.delegate = self
  tableView.registerCells([ProgrammaticJakeCell.self])
  tableView.autoCollapse = true
  tableView.hasSeparator = false
  return tableView
}()

How To Use

Let look step by step how to use Jake.

We have to import Jake package to our class.

import Jake

Secondly we have to implement JakeTableViewDelegateAndDatasourceProtocol protocol to our ViewController.

class ViewController: UIViewController, JakeTableViewDelegateAndDatasourceProtocol { }

After this steps we have to set our delegate.

class ViewController: UIViewController, JakeTableViewDelegateAndDatasourceProtocol {

  override func viewDidLoad() {
    super.viewDidLoad()
    
    jakeTableView.delegate = self
  }
}

Now let's look our functions comes with Jake.

class ViewController: UIViewController, JakeTableViewDelegateAndDatasourceProtocol {

  func jakeTableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, data: [[Any]]) -> UITableViewCell {
    guard let data = data as? [[String (Depends on your model)]] else { return UITableViewCell() }
    
    // Programatic Cell example
    let cell = tableView.dequeueReusableCell(withIdentifier: UITableViewCell.description)
    return cell ?? UITableViewCell()
    
    // Nib Cell Example ("cellID" was define when you register your nib cell in tableView)
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath) as? NibCellTableViewCell
    cell?.refreshTitleWith(title: data[indexPath.section][indexPath.row])
    return cell ?? UITableViewCell()
  }

  // You have to inherit JakeTableViewHeader instead of UIView for your custom header view. isExpended property is inserted for reusable actions.
  func jakeTableView(_ tableView: UITableView, viewForHeaderInSection section: Int, isExpanded: Bool) -> JakeTableViewHeader? {
    let view = JakeTableViewHeader() 
    view.section = section
    return view
  }

  func jakeTableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
  }

  // Optional (It works automatic dimension when not implemented.)
  func jakeTableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 300
  }

  // Optional (It works automatic dimension when not implemented.)
  func jakeTableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    switch section {
    case 0:
      return 50
    default:
      return UITableView.automaticDimension
    }
  }
}

And finally how to register our cells and reload data.

class ViewController: UIViewController, JakeTableViewDelegateAndDatasourceProtocol {

  func registerCell() {
  
    // Nib example
    jakeTableView.registerCells([
      (UINib(nibName: "NibCellTableViewCell", bundle: .main), "cellId") 
    ])
    
    // Programmatic example
    jakeTableView.registerCells([ProgrammaticJakeCell.self])
  }
  
  func reloadData() {
    // You can reload datas ,in format [[Any]]
    jakeTableView.reloadTableViewWith(data: [
      ["1","2","3","4"],
      ["1","2","3","4"],
      ["1","2","3","4"],
      ["1","2","3","4"],
      ["1","2","3","4"]
    ])
  }
}

License

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

jake's People

Watchers

Yusuf Demirci 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.