Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a057a38

Browse files
封装CMHHTTPService网络请求工具类,使用说明详见Example18示例
1. 封装`CMHHTTPService`网络请求工具类,使用说明详见`Example18`示例 2. 封装了解析错误信息的分类 `NSError+MHExtension.h`
1 parent 6c11f49 commit a057a38

File tree

110 files changed

+2372
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2372
-48
lines changed

‎.DS_Store‎

0 Bytes
Binary file not shown.

‎MHDevelopExample/MHDevelopExample.xcodeproj/project.pbxproj‎

Lines changed: 148 additions & 18 deletions
Large diffs are not rendered by default.

‎MHDevelopExample/MHDevelopExample/AppDelegate.m‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ - (void)_configureApplication:(UIApplication *)application initialParamsBeforeIn
8181

8282
// 配置YYWebImage
8383
[self _configureYYWebImage];
84+
85+
/// 配置网络请求
86+
[CMHHTTPService sharedInstance];
8487
}
8588

8689
/// 配置键盘管理器
0 Bytes
Binary file not shown.

‎MHDevelopExample/MHDevelopExample/Architecture/Contacts/Contacts/CMHContactsViewController.m‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "CMHExample15ViewController.h"
1818
#import "CMHExample16ViewController.h"
1919
#import "CMHExample17ViewController.h"
20+
#import "CMHExample18ViewController.h"
2021
@interface CMHContactsViewController ()
2122

2223
@end
@@ -39,7 +40,7 @@ - (void)viewDidLoad {
3940
}
4041
#pragma mark - Override
4142
- (UIEdgeInsets)contentInset{
42-
return UIEdgeInsetsMake(MH_APPLICATION_TOP_BAR_HEIGHT+16, 0, 0, 0);
43+
return UIEdgeInsetsMake(MH_APPLICATION_TOP_BAR_HEIGHT+16, 0, MH_APPLICATION_TAB_BAR_HEIGHT, 0);
4344
}
4445
- (void)configure{
4546
[super configure];
@@ -79,6 +80,10 @@ - (void)configure{
7980
example17.destClass = [CMHExample17ViewController class];
8081
[self.dataSource addObject:example17];
8182

83+
CMHExample *example18 = [[CMHExample alloc] initWithTitle:@"18:请求工具类`CMHHTTPService`的使用" subtitle:@"详情请看`CMHHTTPService.h/m`的封装"];
84+
example18.destClass = [CMHExample18ViewController class];
85+
[self.dataSource addObject:example18];
86+
8287
/// 刷洗数据
8388
// [self.tableView reloadData]; /// 等效下面的方法
8489
[self reloadData];

‎MHDevelopExample/MHDevelopExample/Architecture/Contacts/Example14/CMHExample14ViewController.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ - (void)requestRemoteData{
6767
/// 模拟网络
6868
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
6969

70-
[self.headerView yy_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528468978072&di=e503aaa44a96181286743186d6040522&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018年01月05日%2F5a4f5b0464423.jpg"] placeholder:MHImageNamed(@"placeholder_image") options:MHWebImageOptionAutomatic completion:NULL];
70+
[self.headerView yy_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528468978072&di=e503aaa44a96181286743186d6040522&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018年01月05日%2F5a4f5b0464423.jpg"] placeholder:MHImageNamed(@"placeholder_image") options:CMHWebImageOptionAutomatic completion:NULL];
7171

7272
/// 假设你获取到了ID 你再去获取列表数据
7373
[self tableViewDidTriggerHeaderRefresh];
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// CMHExample18ViewController.h
3+
// MHDevelopExample
4+
//
5+
// Created by lx on 2018年6月21日.
6+
// Copyright © 2018年 CoderMikeHe. All rights reserved.
7+
//
8+
9+
#import "CMHTableViewController.h"
10+
11+
@interface CMHExample18ViewController : CMHTableViewController
12+
13+
@end
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
//
2+
// CMHExample18ViewController.m
3+
// MHDevelopExample
4+
//
5+
// Created by lx on 2018年6月21日.
6+
// Copyright © 2018年 CoderMikeHe. All rights reserved.
7+
//
8+
9+
#import "CMHExample18ViewController.h"
10+
#import "CMHLiveRoomCell.h"
11+
#import "CMHLiveInfo.h"
12+
@interface CMHExample18ViewController ()
13+
14+
@end
15+
16+
@implementation CMHExample18ViewController
17+
/// 重写init方法,配置你想要的属性
18+
- (instancetype)init
19+
{
20+
self = [super init];
21+
if (self) {
22+
/// 支持上拉加载,下拉刷新
23+
self.shouldPullDownToRefresh = YES;
24+
self.shouldPullUpToLoadMore = YES;
25+
26+
/// 是否在用户上拉加载后的数据 , 如果请求回来的数据`小于` pageSize, 则提示没有更多的数据.default is YES 。 如果为`NO` 则隐藏mi_footer 。 前提是` shouldMultiSections = NO `才有效。
27+
self.shouldEndRefreshingWithNoMoreData = NO; // NO
28+
}
29+
return self;
30+
}
31+
32+
- (void)viewDidLoad {
33+
[super viewDidLoad];
34+
/// 设置
35+
[self _setup];
36+
37+
/// 设置导航栏
38+
[self _setupNavigationItem];
39+
40+
/// 设置子控件
41+
[self _setupSubViews];
42+
43+
/// 布局子空间
44+
[self _makeSubViewsConstraints];
45+
}
46+
47+
#pragma mark - 事件处理Or辅助方法
48+
#pragma mark - Override
49+
- (void)tableViewDidTriggerHeaderRefresh{
50+
/// 下拉刷新事件 子类重写
51+
52+
/// 1. 配置参数
53+
CMHKeyedSubscript *subscript = [CMHKeyedSubscript subscript];
54+
subscript[@"useridx"] = @"61856069";
55+
subscript[@"type"] = @(1);
56+
subscript[@"page"] = @(1);
57+
subscript[@"lat"] = @(22.54192103514200);
58+
subscript[@"lon"] = @(113.96939828211362);
59+
subscript[@"province"] = @"广东省";
60+
61+
/// 2. 配置参数模型 #define CMH_GET_LIVE_ROOM_LIST @"Room/GetHotLive_v2"
62+
CMHURLParameters *paramters = [CMHURLParameters urlParametersWithMethod:CMH_HTTTP_METHOD_GET path:CMH_GET_LIVE_ROOM_LIST parameters:subscript.dictionary];
63+
64+
/// 3. 发起请求
65+
[[CMHHTTPRequest requestWithParameters:paramters] enqueueResultClass:CMHLiveRoom.class parsedResult:YES success:^(NSURLSessionDataTask *task, NSArray <CMHLiveRoom *> * responseObject) {
66+
/// 成功后才设置 self.page = 1;
67+
self.page = 1;
68+
/// 添加数据
69+
[self.dataSource removeAllObjects];
70+
[self.dataSource addObjectsFromArray:responseObject];
71+
72+
/// 结束刷新状态
73+
[self tableViewDidFinishTriggerHeader:YES reload:YES];
74+
75+
/// 配置 EmptyView
76+
[self.tableView cmh_configEmptyViewWithType:CMHEmptyDataViewTypeDefault emptyInfo:@"客官别急~,一大波小姐姐正在赶来的路上" errorInfo:nil offsetTop:250 hasData:self.dataSource.count>0 hasError:NO reloadBlock:NULL];
77+
78+
} failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
79+
80+
/// show error
81+
[MBProgressHUD mh_showErrorTips:error addedToView:self.view];
82+
83+
/// 结束刷新状态
84+
[self tableViewDidFinishTriggerHeader:YES reload:NO];
85+
86+
/// 配置 EmptyView
87+
[self.tableView cmh_configEmptyViewWithType:CMHEmptyDataViewTypeDefault emptyInfo:nil errorInfo:[NSError mh_tipsFromError:error] offsetTop:250 hasData:self.dataSource.count>0 hasError:YES reloadBlock:NULL];
88+
}];
89+
90+
}
91+
92+
- (void)tableViewDidTriggerFooterRefresh{
93+
/// 下拉加载事件 子类重写
94+
/// 1. 配置参数
95+
CMHKeyedSubscript *subscript = [CMHKeyedSubscript subscript];
96+
subscript[@"useridx"] = @"61856069";
97+
subscript[@"type"] = @(1);
98+
subscript[@"page"] = @(self.page + 1);
99+
subscript[@"lat"] = @(22.54192103514200);
100+
subscript[@"lon"] = @(113.96939828211362);
101+
subscript[@"province"] = @"广东省";
102+
103+
/// 2. 配置参数模型 #define CMH_GET_LIVE_ROOM_LIST @"Room/GetHotLive_v2"
104+
CMHURLParameters *paramters = [CMHURLParameters urlParametersWithMethod:CMH_HTTTP_METHOD_GET path:CMH_GET_LIVE_ROOM_LIST parameters:subscript.dictionary];
105+
106+
/// 3. 发起请求
107+
[[CMHHTTPRequest requestWithParameters:paramters] enqueueResultClass:CMHLiveRoom.class parsedResult:YES success:^(NSURLSessionDataTask *task, NSArray <CMHLiveRoom *> * responseObject) {
108+
/// 成功后才设置 self.page += 1;
109+
self.page += 1;
110+
/// 添加数据集
111+
[self.dataSource addObjectsFromArray:responseObject];
112+
/// 结束刷新状态
113+
[self tableViewDidFinishTriggerHeader:NO reload:YES];
114+
115+
} failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
116+
/// show error
117+
[MBProgressHUD mh_showErrorTips:error addedToView:self.view];
118+
/// 结束刷新状态
119+
[self tableViewDidFinishTriggerHeader:NO reload:NO];
120+
}];
121+
}
122+
123+
124+
- (void)configure{
125+
[super configure];
126+
}
127+
128+
/// 生成一个可复用的cell
129+
- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
130+
return [CMHLiveRoomCell cellWithTableView:tableView];
131+
}
132+
133+
/// 为Cell配置数据
134+
- (void)configureCell:(CMHLiveRoomCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
135+
[cell configureModel:object];
136+
}
137+
138+
#pragma mark - UITableViewDelegate
139+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
140+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
141+
CMHLiveRoom *liveRoom = self.dataSource[indexPath.row];
142+
CMHViewController *temp = [[CMHViewController alloc] initWithParams:nil];
143+
temp.title = liveRoom.myname;
144+
[self.navigationController pushViewController:temp animated:YES];
145+
}
146+
147+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
148+
CMHLiveRoom *liveRoom = self.dataSource[indexPath.row];
149+
return liveRoom.cellHeight;
150+
}
151+
152+
153+
#pragma mark - 初始化
154+
- (void)_setup{
155+
}
156+
157+
#pragma mark - 设置导航栏
158+
- (void)_setupNavigationItem{
159+
self.navigationItem.title = @"喵播";
160+
}
161+
162+
#pragma mark - 设置子控件
163+
- (void)_setupSubViews{
164+
165+
}
166+
167+
#pragma mark - 布局子控件
168+
- (void)_makeSubViewsConstraints{
169+
170+
}
171+
172+
#pragma mark - Setter & Getter
173+
174+
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// CMHLiveInfo.h
3+
// MHDevelopExample
4+
//
5+
// Created by lx on 2018年6月21日.
6+
// Copyright © 2018年 CoderMikeHe. All rights reserved.
7+
//
8+
9+
#import "CMHObject.h"
10+
#import "CMHLiveRoom.h"
11+
@interface CMHLiveInfo : CMHObject
12+
13+
/// 直播间列表
14+
@property (nonatomic, readwrite, copy) NSArray <CMHLiveRoom *> *list;
15+
16+
/// 总页数
17+
@property (nonatomic, readwrite, assign) NSInteger totalPage;
18+
19+
/// 是否同城
20+
@property (nonatomic, readwrite, assign) BOOL samecity;
21+
22+
/// hotConfig
23+
@property (nonatomic, readwrite, assign) NSInteger hotConfig;
24+
25+
/// hotswitch
26+
@property (nonatomic, readwrite, assign) id hotswitch;
27+
28+
/// hotswitch2
29+
@property (nonatomic, readwrite, copy) NSArray *hotswitch2;
30+
@end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /