BaseListViewController.m 5.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
//
//  BaseListViewController.m
//  RealEstateManagement
//
//  Created by Javen on 16/9/8.
//  Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//

#import "BaseListViewController.h"

@interface BaseListViewController ()

@end

@implementation BaseListViewController

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];

    self.pageSize = 15;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 159;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    if (!self.tableView.tableFooterView) {
        self.tableView.tableFooterView = [UIView new];
    }
    [self paggingMode];
    // Do any additional setup after loading the view.
}

- (void)httpRequest {
    CLog(@"需要重写httpRequest方法");
}

- (void)listDidSelect:(id)model {
    CLog(@"需要重写listDidSelect:方法");
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  启用分页加载(最好在ViewDidLoad里面调用)
 */
- (void)paggingMode {
    WS(weakSelf);
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
Sandy's avatar
Sandy committed
68
        weakSelf.page = 1;
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        [weakSelf.arrData removeAllObjects];
        /**
         *  子类里面要重写httpRequest方法
         */
        [MBProgressHUD j_loading];
        [weakSelf.tableView.mj_footer resetNoMoreData];
        [weakSelf httpRequest];
    }];

    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        weakSelf.page++;
        [weakSelf httpRequest];
    }];
    self.tableView.mj_footer.automaticallyHidden = YES;
}

- (void)refresh {
    [self.tableView.mj_header beginRefreshing];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self listDidSelect:self.arrData[indexPath.row]];
}

#pragma mark - empty state
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:@"list_nodata"];
}

- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    [self.tableView.mj_header beginRefreshing];
}
Sandy's avatar
Sandy committed
110 111 112 113 114 115 116 117 118

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}

- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
    scrollView.contentOffset = CGPointZero;
}

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
- (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 = 1;
    animation.cumulative = YES;
    animation.repeatCount = MAXFLOAT;

    return animation;
}

- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIColor whiteColor];
}

- (IBAction)actionAdd:(UIButton *)sender {
}

- (void)listPushCustomAnimate:(BaseViewController *)VC {
    WS(weakSelf);
    VC.commplete = ^{
        [weakSelf.tableView.mj_header beginRefreshing];
    };
    CGPoint point = self.btnAdd.center;
    XWCircleSpreadAnimator *animator = [XWCircleSpreadAnimator xw_animatorWithStartCenter:point radius:30];
    [self.navigationController xw_pushViewController:VC withAnimator:animator];
}

- (void)listTableViewReloadData {
    [MBProgressHUD j_hideLoadingView];
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
    [self.tableView reloadData];
    
    //停止刷新的逻辑
    if (self.tableView.mj_header.isRefreshing) {
        //下拉刷新
        [self.tableView.mj_header endRefreshing];

    } else if (self.tableView.mj_footer.isRefreshing) {
        [self.tableView.mj_footer endRefreshing];
    }

    if (self.arrData.count < self.pageSize * (self.page + 1)) {
        [self.tableView.mj_footer endRefreshingWithNoMoreData];
    } else {
        [self.tableView.mj_footer resetNoMoreData];
    }

    if (self.arrData.count > 0 && self.page == 0) {
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
    }
    
    
}

- (void)judgeFooterNomoreDate {
}

- (void)listTableViewReloadDataWithNewRecord:(NSArray *)newRecord {
    [self listTableViewReloadData];
    CLog(@"newrecord count = %lu", newRecord.count);
    if ([newRecord count] < self.pageSize) {
        [self.tableView.mj_footer endRefreshingWithNoMoreData];
    }
}
- (NSMutableArray *)arrData {
    if (!_arrData) {
        _arrData = [NSMutableArray array];
    }
    return _arrData;
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end