DZNEmptyDataSet的功能是展现UITableView或者UICollectionView没有数据时候的占位图. 阅读以后发现, 实现的思路仍是很是好的.学习
DZNEmptyDataSet是经过代理方法实现主要功能的, 其无数据时候的文字说明, 占位图等等等信息所有都是经过代理方法来获取的, 这样咱们能够经过代理方法, 彻底自定义展现内容的样式, 使用起来灵活性更高.代理
DZNEmptyDataSet的实现, 在设置代理的时候, 利用Method Swizzling
技术交换了方法的实现, 实际上系统调用UITableView的reloadData方法时候, 会调用到DZNEmptyDataSet中分类的一个方法, 这个方法实现了加载一个自定义的view, 并将元素放到tableView上面去, 例如获取标题信息方式以下所示:code
// 返回标题的 attributedString, 经过代理方法获取 - (NSAttributedString *)dzn_titleLabelString { if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(titleForEmptyDataSet:)]) { NSAttributedString *string = [self.emptyDataSetSource titleForEmptyDataSet:self]; if (string) NSAssert([string isKindOfClass:[NSAttributedString class]], @"You must return a valid NSAttributedString object for -titleForEmptyDataSet:"); return string; } return nil; } //从代理方法中获取标题信息 NSAttributedString *titleLabelString = [self dzn_titleLabelString];
经过阅读这个类学习到的是:string