当视图内容为空时使用的一种简单方式
CocoaPods 安装:pod 'WYNullView'
导入主文件:#import "WYNullView.h"
在空状态下显示默认内容,然后您所需要做的就是
if (showNullView) { // 无数据,empty data -》 show nullview
[self.tableView wy_showNullView];
} else { // 有数据,data -》 hide nullview
[self.tableView wy_hideNullView];
}
if (showNullView) { // 无数据,empty data -》 show nullview
[self.tableView wy_showNullView:^UIView *(NullView *defaultNullView) {
// you can do any constom operation in this block, even return a new constom UIView obj
// rerurn [UIView new];
defaultNullView.desText = @"基于NullView自定义";
defaultNullView.frame = CGRectMake(10, 10, defaultNullView.frame.size.width, defaultNullView.frame.size.height);
defaultNullView.backgroundColor = [UIColor cyanColor];
return defaultNullView;
} heightOffset:0.0];
} else { // 有数据,data -》 hide nullview
[self.tableView wy_hideNullView];
}
///> 空视图
@property (nonatomic, strong) UIView *wy_nullView;
寻找NullView链
NullViewHandle 类型
typedef UIView *(^NullViewHandle)(NullView *defaultNullView);
不同的方法可以用不同的方式使用
[UIView wy_configGlobleNullView:^UIView *(NullView *defaultNullView) {
// return globalNullView...
}];
- (void)viewDidLoad {
[mView wy_configNullView:^UIView *(NullView *defaultNullView) {
// return nullView...
}];
}
- (void)func1 {
...
[mView wy_showNullView];
...
}
- (void)func2 {
...
[mView wy_showNullView];
...
}
- (void)func1 {
...
[mView wy_showNullView:^UIView *(NullView *defaultNullView) {
// return nullView...
} heightOffset:0.0]];
...
}
- (void)func2 {
...
[mView wy_showNullView:^UIView *(NullView *defaultNullView) {
// return nullView...
} heightOffset:0.0]];
...
}
控制特殊子视图的显示/隐藏
// add objc_whitelist
[[mView wy_objWhitelist] addObject:makeWeakReference(mView_subView)];
// add class_whitelist
[[self.tableView wy_classWhitelist] addObject:makeWeakReference([mView_subView class])];
如果您认为它有用,请为我 star,自由分享您的想法,Issue 或 pull requests
MIT