Latest 1.0.6
Homepage https://github.com/Minitour/AZRemoteTable
License MIT
Platforms ios 10.0
Authors

Loading remote data was never this easy

[CocoaPods]()
[CocoaPods]()
[CocoaPods]()

AZRemoteTable AZRemoteTable

Features

  • [x] Automatically loads more when scrolling 🚀
  • [x] Pull to refresh support 🏓
  • [x] Works with any UITableView! 🎯
  • [x] Error handling 🕸
  • [x] Custom view and sub-classing 🎨

Installation

pod 'AZRemoteTable'

Or simply drag and drop Sources folder to your project.

Usage

Step #1: Create a Data Source

class CustomRemoteDataSource: AZRemoteTableDataSource {

    //An array in which we will store the data.
    fileprivate var items: [String] = []

    /// Helper function to add items.
    public func addItems(items: [String]){
        for item in items { self.items.append(item) }
    }

    /// Helper function to clear items.
    public func clearItems() {
        items.removeAll()
        reset()
    }

    // MARK: - AZRemoteTableDataSource

    override func cellForRowAt(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
        //simple implementation of cellForRowAt:
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
        cell.textLabel?.text = items[indexPath.row]
        return cell
    }

    override func numberOfRowsInSection(_ tableView: UITableView, section: Int) -> Int {
        //return the number of items currently held.
        return items.count
    }
}

Step #2: Create a Delegate

class CustomRemoteDelegate: AZRemoteTableDelegate {
    override func tableView(_ tableView: UITableView,
                            didRequestPage page: Int,
                            usingRefreshControl: Bool) {

        // Make an API call.
        APIManager.shared.loadData(id: "a9dd9e00-55f8-4ce8-8ada-8e933d052e3a",
                                   token: "b54695d5-6f98-442f-9b39-4509fcd8aacd",
                                   page: page,
                                   itemsPerPage: 30) { (message, data, error) in

            //check for errors
            if error {
                //error found, notify table
                tableView.remote.notifyError()
            }else {
                //all good, data fetched, add it to the data source.
                let dataSource = tableView.remote.dataSource as? CustomRemoteDataSource

                //clear all items if we used pull to refresh
                if usingRefreshControl { dataSource?.clearItems() }

                //update data source
                dataSource?.addItems(items: data)

                //notify table that we are done, and if we have more data to load.
                tableView.remote.notifySuccess(hasMore: true)
            }
        }
    }
}

Step #3: Use it in your controller

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    let delegate = CustomRemoteDelegate()
    let dataSource = CustomRemoteDataSource()

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = delegate
        tableView.dataSource = dataSource
        tableView.remote.initialLoad()
    }
}

Latest podspec

{
    "name": "AZRemoteTable",
    "version": "1.0.6",
    "summary": "A framework that makes loading remote data into a table view an easy task.",
    "homepage": "https://github.com/Minitour/AZRemoteTable",
    "license": "MIT",
    "authors": {
        "Antonio Zaitoun": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/Minitour/AZRemoteTable.git",
        "tag": "1.0.6"
    },
    "source_files": "Sources/*.swift"
}

Pin It on Pinterest

Share This