forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointRecordsViewController.m
More file actions
166 lines (149 loc) · 6.27 KB
/
PointRecordsViewController.m
File metadata and controls
166 lines (149 loc) · 6.27 KB
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
164
165
166
//
// PointRecordsViewController.m
// Coding_iOS
//
// Created by Ease on 15/8/5.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "PointRecordsViewController.h"
#import "WebViewController.h"
#import "ShopViewController.h"
#import "Coding_NetAPIManager.h"
#import "SVPullToRefresh.h"
#import "ODRefreshControl.h"
#import "PointTopCell.h"
#import "PointShopCell.h"
#import "PointRecordCell.h"
@interface PointRecordsViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) PointRecords *curRecords;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *refreshControl;
@end
@implementation PointRecordsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"我的码币";
self.curRecords = [PointRecords new];
// 添加myTableView
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
tableView.backgroundColor = [UIColor clearColor];
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerClass:[PointTopCell class] forCellReuseIdentifier:kCellIdentifier_PointTopCell];
[tableView registerClass:[PointShopCell class] forCellReuseIdentifier:kCellIdentifier_PointShopCell];
[tableView registerClass:[PointRecordCell class] forCellReuseIdentifier:kCellIdentifier_PointRecordCell];
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
tableView;
});
_refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
__weak typeof(self) weakSelf = self;
[_myTableView addInfiniteScrollingWithActionHandler:^{
[weakSelf refreshMore];
}];
[self refresh];
}
- (void)refresh{
if (_curRecords.isLoading) {
return;
}
_curRecords.willLoadMore = NO;
[self sendRequest];
}
- (void)refreshMore{
if (_curRecords.isLoading || !_curRecords.canLoadMore) {
return;
}
_curRecords.willLoadMore = YES;
[self sendRequest];
}
- (void)sendRequest{
if (_curRecords.list.count <= 0) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_PointRecords:_curRecords andBlock:^(id data, NSError *error) {
[weakSelf.refreshControl endRefreshing];
[weakSelf.view endLoading];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
[weakSelf.curRecords configWithObj:data];
[weakSelf.myTableView reloadData];
weakSelf.myTableView.showsInfiniteScrolling = weakSelf.curRecords.canLoadMore;
}
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.curRecords.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
#pragma mark Table M
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _curRecords.list.count <= 0? 0:2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return section == 0? 2: self.curRecords.list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
if (indexPath.row == 0) {
PointRecord *record = [_curRecords.list firstObject];
PointTopCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_PointTopCell forIndexPath:indexPath];
cell.pointLeftStr = [NSString stringWithFormat:@"%.2f", record.points_left.floatValue];
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:0 hasSectionLine:NO];
return cell;
}else{
PointShopCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_PointShopCell forIndexPath:indexPath];
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:0];
return cell;
}
}else{
PointRecord *record = [_curRecords.list objectAtIndex:indexPath.row];
PointRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_PointRecordCell forIndexPath:indexPath];
cell.curRecord = record;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat cellHeight = 0;
if (indexPath.section == 0) {
cellHeight = indexPath.row == 0? [PointTopCell cellHeight]: [PointShopCell cellHeight];
}else{
cellHeight = [PointRecordCell cellHeight];
}
return cellHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return section == 0? 20.0 : 0.5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.5;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *footerView = [UIView new];
footerView.backgroundColor = kColorTableSectionBg;
return footerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [UIView new];
view.backgroundColor = kColorTableSectionBg;
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0 && indexPath.row == 1) {
//商城入口
// WebViewController *vc = [WebViewController webVCWithUrlStr:@"/shop/"];
// [self.navigationController pushViewController:vc animated:YES];
ShopViewController *shopvc = [[ShopViewController alloc] init];
[self.navigationController pushViewController:shopvc animated:YES];
}
}
@end