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
68
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
110
111
112
113
114
115
116
117
118
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
//
// 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.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
self.tableView.estimatedRowHeight = 159;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.tableFooterView = [UIView new];
[self paggingMode];
// Do any additional setup after loading the view.
}
- (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:^{
weakSelf.page = 0;
[weakSelf.arrData removeAllObjects];
/**
* 子类里面要重写httpRequest方法
*/
[MBProgressHUD j_loading];
[weakSelf httpRequest];
}];
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
weakSelf.page++;
[weakSelf httpRequest];
}];
self.tableView.mj_footer.hidden = YES;
}
- (void)refresh
{
[self.tableView.mj_header beginRefreshing];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.arrData.count;
}
- (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_no_data"];
}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view
{
[self.tableView.mj_header beginRefreshing];
}
- (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)listTableViewReloadData
{
[MBProgressHUD j_hideLoadingView];
[self.tableView reloadData];
[self.tableView j_endRefresh];
self.tableView.mj_footer.hidden = self.arrData.count == 0;
if (self.arrData.count < self.pageSize * self.page) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
}
- (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