TBEmptyDataSet
TBEmptyDataSet是UITableView/UICollectionView的超级类扩展,当tableView/collectionView的数据为空时,它将显示一个占位符emptyDataSet。
TBEmptyDataSet可以由一个图像、一个标题和一个描述组成,或者您可以将其设置为自定义视图。
如何开始
Carthage
在您的Cartfile
中指定"TBEmptyDataSet"。
github "teambition/TBEmptyDataSet"
CocoaPods
在您的Podfile
中指定"TBEmptyDataSet"。
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'TBEmptyDataSet'
用法
1. 分配数据源和代理
tableView.emptyDataSetDataSource = self
tableView.emptyDataSetDelegate = self
2. 实现数据源和代理
数据源函数
func imageForEmptyDataSet(in scrollView: UIScrollView) -> UIImage? {
// return the image for EmptyDataSet
}
func titleForEmptyDataSet(in scrollView: UIScrollView) -> NSAttributedString? {
// return the title for EmptyDataSet
}
func descriptionForEmptyDataSet(in scrollView: UIScrollView) -> NSAttributedString? {
// return the description for EmptyDataSet
}
func imageTintColorForEmptyDataSet(in scrollView: UIScrollView) -> UIColor? {
// return the image tint color for EmptyDataSet
}
func backgroundColorForEmptyDataSet(in scrollView: UIScrollView) -> UIColor? {
// return the backgroundColor for EmptyDataSet
}
func verticalOffsetForEmptyDataSet(in scrollView: UIScrollView) -> CGFloat {
// return the vertical offset for EmptyDataSet, default is 0
}
func verticalSpacesForEmptyDataSet(in scrollView: UIScrollView) -> [CGFloat] {
// return the vertical spaces from top to bottom for EmptyDataSet, default is [12, 12]
}
func titleMarginForEmptyDataSet(in scrollView: UIScrollView) -> CGFloat {
// return the minimum horizontal margin space for title, default is 15
}
func descriptionMarginForEmptyDataSet(in scrollView: UIScrollView) -> CGFloat {
// return the minimum horizontal margin space for description, default is 15
}
func customViewForEmptyDataSet(in scrollView: UIScrollView) -> UIView? {
// return an UIView instance for EmptyDataSet
}
代理函数
func emptyDataSetShouldDisplay(in scrollView: UIScrollView) -> Bool {
// should display EmptyDataSet or not, default is true
}
func emptyDataSetTapEnabled(in scrollView: UIScrollView) -> Bool {
// enable tap gesture or not, default is true
}
func emptyDataSetScrollEnabled(in scrollView: UIScrollView) -> Bool {
// scrollView can scroll or not, default is false
}
func emptyDataSetDidTapEmptyView(in scrollView: UIScrollView) {
// do something
}
func emptyDataSetWillAppear(in scrollView: UIScrollView) {
// do something
}
func emptyDataSetDidAppear(in scrollView: UIScrollView) {
// do something
}
func emptyDataSetWillDisappear(in scrollView: UIScrollView) {
// do something
}
func emptyDataSetDidDisappear(in scrollView: UIScrollView) {
// do something
}
3. 数据源事件(插入、删除、重新加载等)
TBEmptyDataSet将在表视图或集合视图的数据源改变时自动更新。
具体来说
- 对于UITableView,当调用
endUpdates()
时更新。 - 对于UITableView和UICollectionView,当调用
performBatchUpdates(_:completion:)
完成时更新。 - 对于UITableView和UICollectionView,当调用
reloadData()
时更新。
最低版本要求
iOS 8.0
发行说明
许可协议
TBEmptyDataSet采用MIT许可协议发布。有关详细信息,请参阅LICENSE。
更多信息
有问题?请提交一个问题!