123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // MACTableView.m
- // WeSchoolTeacher
- //
- // Created by MacKun on 16/3/1.
- // Copyright © 2016年 solloun. All rights reserved.
- //
- #import "MACTableView.h"
- #import "MACRefreshHeader.h"
- #import "MJRefreshAutoFooter.h"
- @interface MACTableView()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>{
-
- }
- /**
- * 是否第一次加载就展示空白页 默认为YES
- */
- @property(nonatomic,assign)BOOL firstShowEmpty;
- @end
- @implementation MACTableView
- -(instancetype)initWithCoder:(NSCoder *)aDecoder{
- self=[super initWithCoder:aDecoder];
- if (self) {
- [self initUI];
- }
- return self;
- }
- -(instancetype)initWithFrame:(CGRect)frame{
- self =[super initWithFrame:frame];
- if (self) {
- [self initUI];
- self.firstShowEmpty = NO;
- }
- return self;
- }
- -(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
- self =[super initWithFrame:frame style:style];
- if (self) {
- [self initUI];
- self.firstShowEmpty = NO;
- }
- return self;
- }
- -(void)initUI{
- self.tableFooterView = [UIView new];
- self.titleForEmpty = @"咋没数据呢,刷新试试~~";
- self.descriptionForEmpty = @"您的数据被程序猿搬走咯~~";
- self.imageNameForEmpty = @"placeholder_dropbox";
- self.firstShowEmpty = NO;
- self.isRefresh = YES;
- self.isLoadMore = YES;
- self.isShowEmpty = NO;
- self.showsHorizontalScrollIndicator = NO;
- self.showsVerticalScrollIndicator = NO;
-
- self.page = 0;
- }
- -(void)setMacTableViewDelegate:(id<MACTableViewDelegate>)macTableViewDelegate{
- _macTableViewDelegate = macTableViewDelegate;
- self.dataSource = (id<UITableViewDataSource>)macTableViewDelegate;
- self.delegate = (id<UITableViewDelegate>)macTableViewDelegate;
- }
- -(void)setIsRefresh:(BOOL)isRefresh{
- _isRefresh = isRefresh;
- if (isRefresh) {
- // header
- [self setMj_header:
- [MJRefreshStateHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)]];
- [self.mj_header setMultipleTouchEnabled:NO];
- }else{
- [self setMj_header:nil];
- }
- }
- -(void)setIsShowEmpty:(BOOL)isShowEmpty{
- _isShowEmpty = isShowEmpty;
- if (isShowEmpty) {
- self.emptyDataSetDelegate = self;
- self.emptyDataSetSource = self;
- }
- }
- -(void)setIsLoadMore:(BOOL)isLoadMore{
- _isLoadMore = isLoadMore;
- if (isLoadMore) {
- if (self.mj_footer==nil) {
- [self setMj_footer:[MJRefreshAutoNormalFooter
- footerWithRefreshingBlock:^{
- // 加载下一页在这
- // [self showWaiting];
-
- if (_macTableViewDelegate && [_macTableViewDelegate respondsToSelector:@selector(loadDataRefreshOrPull:)]) {
- [_macTableViewDelegate loadDataRefreshOrPull:MACPulling];
- }
-
- }]
- ];
- }
- [self.mj_footer setMultipleTouchEnabled:NO];
- }else{
- [self setMj_footer:nil];
- }
- }
- -(void)beginLoading{
- [self.mj_header beginRefreshing];
- }
- -(void)endLoading{
- if([self.mj_header isRefreshing])
- [self.mj_header endRefreshing];
- if ([self.mj_footer isRefreshing])
- [self.mj_footer endRefreshing];
- }
- -(void)refreshData{
- // [self showWaiting];
- if (self.mj_footer.state == MJRefreshStateNoMoreData) {
- [self.mj_footer resetNoMoreData];
- }
- if (_macTableViewDelegate && [_macTableViewDelegate respondsToSelector:@selector(loadDataRefreshOrPull:)]) {
- self.page = 0;
- [_macTableViewDelegate loadDataRefreshOrPull:MACRefreshing];
- }
- }
- -(NSNumber *)getCurrentPage{
- return [NSNumber numberWithInteger:++self.page];
- }
- #pragma mark - DZNEmptyDataSetSource Methods
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text = self.titleForEmpty;
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0f],
- NSForegroundColorAttributeName: [UIColor darkGrayColor]};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text = self.descriptionForEmpty;
- NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
- paragraph.lineBreakMode = NSLineBreakByWordWrapping;
- paragraph.alignment = NSTextAlignmentCenter;
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f],
- NSForegroundColorAttributeName: [UIColor lightGrayColor],
- NSParagraphStyleAttributeName: paragraph};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
- {
- // if (!self.imageNameForEmpty || [self.imageNameForEmpty isBlank]) {
- // return nil;
- // }
- return [UIImage imageNamed:self.imageNameForEmpty];
- }
- - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [UIColor whiteColor];
- }
- - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
- {
- return -20.0f;
- }
- - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
- {
- return 0.0f;
- }
- #pragma mark - DZNEmptyDataSetDelegate Methods
- - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
- {
- if (self.firstShowEmpty) {
- self.firstShowEmpty = NO;
-
- return NO;
- }
-
- return YES;
- }
- - (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView
- {
- return YES;
- }
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
- {
- return YES;
- }
- - (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView
- {
- CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"];
- animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
- animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
- animation.duration = 0.25;
- animation.cumulative = YES;
- animation.repeatCount = MAXFLOAT;
-
- return animation;
- }
- @end
|