TableViewDataStatus 2.0.0

TableViewDataStatus 2.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Gabriel Massana.



  • By
  • Gabriel Massana

TableViewDataStatus-iOS

What is it?

Table View to control Data Status.

  • Allows to add a loading view as subview.
  • Allows to add an empty view as subview.

The table view automatically controls the visibility of the views.

Installation

Podfile

platform :ios, '8.0'
use_frameworks!

pod 'TableViewDataStatus', '~> 1.0'

Then, run the following command:

$ pod install

Old school

Drag into your project the folder /TableViewDataStatus-iOS. That’s all.

Example Swift

On the example the empty view is a simple UIView with orangeColor() background. The loading view is the same but with greenColor() background.

On production they can be any UIView subview with any elements.

     /**
     Empty View to be shown when no data in the Table View.
     */
    lazy var emptyView: UIView = {

        let emptyView: UIView = UIView(frame: CGRect.init(x: 0.0, y: 0.0, width: CGRectGetWidth(UIScreen.mainScreen().bounds), height: CGRectGetHeight(UIScreen.mainScreen().bounds)))

        emptyView.backgroundColor = UIColor.orangeColor()

        return emptyView
    }()

    /**
     Empty View to be shown when no data in the Table View.
     */
    lazy var loadingView: UIView = {

        let loadingView: UIView = UIView(frame: CGRect.init(x: 0.0, y: 0.0, width: CGRectGetWidth(UIScreen.mainScreen().bounds), height: CGRectGetHeight(UIScreen.mainScreen().bounds)))

        loadingView.backgroundColor = UIColor.greenColor()

        return loadingView
    }()

    /**
     Table view to display data.
     */
    lazy var tableView: TableViewDataStatus = {

        let tableView: TableViewDataStatus = TableViewDataStatus.init(frame: UIScreen.mainScreen().bounds, style: .Plain)

        tableView.emptyView = self.emptyView
        tableView.loadingView = self.loadingView

        return tableView
    }()

    /**
     Fake API call method. 
     At the begining of the method willLoadContent() is called to update the loadingView visibility.
     At the end of the APi call didFinishLoadingContent() is called to update again the views visibilities.
     */
    func fakeAPICallAndComplition() {

        // Call this method before the API call.
        tableView.willLoadContent()

        let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(5.0 * Double(NSEC_PER_SEC)))

        dispatch_after(delayTime, dispatch_get_main_queue()) {

            // Call this method on finish the API call.
            self.tableView.didFinishLoadingContent(false)
        }
    }    

Example Objective-C

#import "TableViewDataStatus-Swift.h"

License

TableViewDataStatus-iOS is released under the MIT license. Please see the file called LICENSE.

Versions

$ git tag -a 1.0.0 -m 'Version 1.0.0'

$ git push --tags

Author

Gabriel Massana

Found an issue?

Please open a new Issue here if you run into a problem specific to TableViewDataStatus-iOS, have a feature request, or want to share a comment.