UIEmptyState 5.0.0

UIEmptyState 5.0.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2021年1月
SPM支持SPM

Luis PadronLuis Padron维护。




banner

要求

  • Xcode 9.0+
  • iOS 9.0或更高版本

安装

CocoaPods

  1. 安装CocoaPods
  2. 将此仓库添加到您的Podfile
target 'Example' do
  use_frameworks!
	
  pod 'UIEmptyState'
end
  1. 运行pod install
  2. 打开CocoaPods生成的新的.xcworkspace
  3. 当您想要使用库时: import UIEmptyState

Carthage

  1. 确保Carthage已安装

    brew install carthage

  2. 将此仓库添加到您的Cartfile

    github "luispadron/UIEmptyState"

手动

  1. 简单下载 UIEmptyState 源文件并将它们导入到你的项目。

使用方法

只要使用的是 UIViewController 子类,你将获得默认的符合性,以及 reloadEmptyState 方法。

// No subclassing required, simply conform to the two protocols
class ViewController: UITableViewController, UIEmptyStateDataSource, UIEmptyStateDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Set the data source and delegate
        self.emptyStateDataSource = self
        self.emptyStateDelegate = self
        // Optionally remove seperator lines from empty cells
        self.tableView.tableFooterView = UIView(frame: CGRect.zero)
   }
   
   override func viewDidAppear(_ animated: Bool) {
   	super.viewDidAppear(animated)
	// Set the initial state of the tableview, called here because cells should be done loading by now
	// Number of cells are used to determine if the view should be shown or not
	self.reloadEmptyState()
   }
}

每当需要重新加载空状态视图时,例如数据变化导致表格视图数据源变化,请在 UITableViewControllerUICollectionViewController 中调用 self.reloadEmptyState()。如果是在常规的 UIViewController 中,请确保调用适当的 reloadEmptyStateForTableView(_:)reloadEmptyStateForCollectionView(_:) 方法。

示例

// Inside a UITableViewController subclass

func foo() {
	// My data has changed here, I want to my tableview, 
	// and in case I no longer have data (user deleted, etc) also reload empty view
	self.tableView.reloadData()
	// Reload empty view as well
	self.reloadEmptyState()
}

func deleteFoo() {
	// This works too, just call after end updates
	tableView.beginUpdates()
	fooSource.remove(at: indexPath.row)
	tableView.deleteRows(at: [indexPath], with: .automatic)
	tableView.endUpdates()
	// Call reload of empty state 
	self.reloadEmptyState()
}

如果您需要更多帮助,请查看此处的示例项目(喜欢宝可梦的 nerds 会喜欢它):示例

文档

在此处阅读完整文档

示例项目

  1. 克隆此仓库
  2. 进入 Example 目录
  3. 运行pod install

许可 (MIT)

Copyright (c) 2017 Luis Padron

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.