Coder Social home page Coder Social logo

pagingtableview's Introduction

PagingTableView

Version License: MIT Platform Swift 3.1

The simplest way to add paginate (a.k.a infinite scroll) function to your table view.
All you have to do is just set your table view class in the storyboard to PagingTableView, and implement the PagingTableViewDelegate#paginate

Installation

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

pod "PagingTableView"

Example

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

Usage

First set your table view class in the storyboard to PagingTableView

Then implement paginate function. If isLoading is set to true, an indicator is displayed at the bottom of the table view. Otherwise, the indicator disappears and UITableView.reloadData is called.

class MainViewController: UIViewController {

  override func viewDidLoad() {
    ...
    contentTable.pagingDelegate = self
  }

  ...

}

extension MainViewController: PagingTableViewDelegate {

  func paginate(_ tableView: PagingTableView, to page: Int) {
    contentTable.isLoading = true
    contentDataSource.loadData(at: page) { contents in
      self.contents.append(contentsOf: contents)
      self.contentTable.isLoading = false
    }
  }

}

See example for more information.

APIs

Name Type Description
pagingDelegate PagingTableViewDelegate Delegate pagination processing
currentPage Int Returns the current page
isLoading Bool Shows and hides the loading indicator. Reload table view data after loading
reset() Void Return page to 0 and call paginate function

Author

InJung Chung / @mu29

License

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

pagingtableview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pagingtableview's Issues

Unable to make it call delegate method

Hello,

I have set everything like in example. Unfortunately,

 func paginate(_ tableView: PagingTableView, to page: Int) {
 }

method does not being called when I am at the end of the uitableview.

What might be the wrong?

Error on layout constraints

I received this when using this

Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000024d45a0 UIImageView:0x7fb5fc5a9c40.height == 60   (active)>",
    "<NSLayoutConstraint:0x6000024d4910 UIImageView:0x7fb5fc5a9c40.top == UILabel:0x7fb5fe846a20'Blood Donation Drive'.top   (active)>",
    "<NSLayoutConstraint:0x6000024d49b0 UILabel:0x7fb5fe846a20'Blood Donation Drive'.top == UITableViewCellContentView:0x7fb5fc5a9a50.topMargin + 10   (active)>",
    "<NSLayoutConstraint:0x6000024d4820 UITableViewCellContentView:0x7fb5fc5a9a50.bottomMargin >= UIImageView:0x7fb5fc5a9c40.bottom + 10   (active)>",
    "<NSLayoutConstraint:0x6000024d9590 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x600003ed07e0'UIViewLayoutMarginsGuide']-(8)-|   (active, names: '|':UITableViewCellContentView:0x7fb5fc5a9a50 )>",
    "<NSLayoutConstraint:0x6000024d0a00 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fb5fc5a9a50.height == 96   (active)>",
    "<NSLayoutConstraint:0x6000024da5d0 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x600003ed07e0'UIViewLayoutMarginsGuide']   (active, names: '|':UITableViewCellContentView:0x7fb5fc5a9a50 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000024d45a0 UIImageView:0x7fb5fc5a9c40.height == 60   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

I'm using UITableView.automaticDimension for row height

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.