TableViewDataStatus 2.0.0

TableViewDataStatus 2.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年10月
SwiftSwift 版本3.0
SPM支持 SPM

Gabriel Massana 维护。



  • 作者:
  • Gabriel Massana

TableViewDataStatus-iOS

它是做什么的?

控制数据状态的 Table View。

  • 允许添加一个加载视图作为子视图。
  • 允许添加一个空视图作为子视图。

表格视图将自动控制视图的可见性。

安装

Podfile

platform :ios, '8.0'
use_frameworks!

pod 'TableViewDataStatus', '~> 1.0'

然后,运行以下命令

$ pod install

传统方式

将文件夹 /TableViewDataStatus-iOS 拖入到您的项目中。就这样。

Swift 示例

在示例中,空视图是一个简单的 UIView,背景为 orangeColor()。加载视图与之相同,但背景为 greenColor()。

在实际应用中,它们可以是任何带有任何元素的 UIView 子视图。

     /**
     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)
        }
    }    

Objective-C 示例

#import "TableViewDataStatus-Swift.h"

许可证

TableViewDataStatus-iOS 在 MIT 许可证下发布。请参阅名为 LICENSE 的文件。

版本

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

$ git push --tags

作者

Gabriel Massana

找到了一个问题?

如果您遇到TableViewDataStatus-iOS的特定问题,有功能请求或想要分享评论,请在以下地方打开一个新问题