ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - AfrozZaheer/AZTableViewController: Elegant and easy way to integrate pagination with dummy views
Elegant and easy way to integrate pagination with dummy views  - GitHub - AfrozZaheer/AZTableViewController: Elegant and easy way to integrate pagination with dummy views
Visit Site

GitHub - AfrozZaheer/AZTableViewController: Elegant and easy way to integrate pagination with dummy views

GitHub - AfrozZaheer/AZTableViewController: Elegant and easy way to integrate pagination with dummy views

AZTableView Controller

Alt text

Awesome Swift version Support Dependecy Manager Version License Platform

Features

  • Automatic pagination handling
  • No more awkward empty TableView screen
  • AZ TableView controller give you advantage to connect your (Loading, no result, error ) views via Interface builder

New in version 0.0.2

  • You can now add your custom xib as dummy views (loading, error, no result)
  • You can add xib based next page loading cell also

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate AZTableViewController into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
pod 'AZTableView'
end

Then, run the following command:

$ pod install

Usage

Step 1

  • Extend your view controller from AZTableVIewController

class ViewController: AZTableViewController {

    var lastIndex = 0
    var results = [String]()
    override func viewDidLoad() {

        super.viewDidLoad()
        self.fetchData()
    }

    override func viewDidAppear(_ animated: Bool) {

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

Step 2

  • Set the next page loading cell outlet as given below,

Alt text

Alt text

  • To load views from custom .xib files

class ViewController: AZTableViewController {
    override func viewDidLoad() {

        self.loadLoadingView(nibName: "your nib name") // if bundle is nil
        self.loadErrorView(nibName: "your nib name", bundle: yourBundle) // if custom bundle

        super.viewDidLoad()
        self.fetchData()
    }
}
  • If your xibs are in main bundle than use
    self.loadLoadingView(nibName: "your nib name") // if bundle is nil

Else use

    self.loadLoadingView(nibName: "your nib name", bundle: yourBundle)

Step 3

  • Confirm your controller to UITableViewDelegate and UITableViewDataSource

  • And override AZtabeView cellForRow function.

extension ViewController : UITableViewDataSource, UITableViewDelegate {

    override func AZtableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        if let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
        {
            cell.textLabel?.text = results[indexPath.row]
            return cell
        }
        return UITableViewCell()
    }
    
    override func AZtableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return results.count
    }
}


Step 4

  • Override two more functions "fetchData" and "fetchNextData"
//MARK: - API Call
extension ViewController {
    
    override func fetchData() {
        super.fetchData()
        
        FakeService.getData { (error, results) in
           
            if let resu = results {
                self.results.removeAll()
                self.results.append(contentsOf: resu)
                self.didfetchData(resultCount: resu.count, haveMoreData: true)
            }
                
            else if let error = error {
                self.errorDidOccured(error: error)
            }
        }
    }
    
    override func fetchNextData() {
        super.fetchNextData()
        
        FakeService.getData (offset: results.count) { (error, results) in
            
            if let resu = results {
                
                self.results.append(contentsOf: resu)
                if self.results.count < 45 { // you probably get next page exist from service.
                    self.didfetchData(resultCount: resu.count, haveMoreData: true)
                }
                else {
                    self.didfetchData(resultCount: resu.count, haveMoreData: false)
                }
            }
            else if let error = error {
                self.errorDidOccured(error: error)
            }
        }
    }
}

Done

Thats it, you successfully integrate AZTableViewController

License

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

Author

Afroz Zaheer - (https://github.com/AfrozZaheer)

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory