SearchPOIListViewController.m
6.01 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
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
//
// SearchPOIListViewController.m
// IM_ios_client
//
// Created by zsq on 2018/9/6.
// Copyright © 2018年 xiniu. All rights reserved.
//
#import "SearchPOIListViewController.h"
#import "YYSearchView.h"
@interface SearchPOIListViewController ()<AMapSearchDelegate>
{
YYSearchView * searchView;
UIView *v_top;
UITableView *tab_result;
UIView *noResultView;
NSMutableArray *muarr_list;
}
@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic, strong) AMapSearchAPI *search;
@end
@implementation SearchPOIListViewController
- (void)dealloc{
self.search.delegate = nil;
}
- (void)viewDidLoad {
[super viewDidLoad];
muarr_list = [[NSMutableArray alloc]init];
self.search = [[AMapSearchAPI alloc] init];
self.search.delegate = self;
v_top = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, TOP_OFFSET)];
v_top.backgroundColor = COLOR_C_f4f4f4;
searchView = [YYSearchView creatView];
searchView.frame = CGRectMake(0, kStatusBarHeight, ScreenWidth, 44);
searchView.YYSearch.delegate = self;
searchView.YYSearch.returnKeyType = UIReturnKeySearch;
[searchView.YYSearch becomeFirstResponder];
__weak __typeof(self) weakSelf = self;
[searchView setYYGetCancel:^{
[weakSelf dismissViewControllerAnimated:NO completion:nil];
}];
[searchView setYYGetTitle:^(NSString * title)
{
NSString *trimedString = [CommonFun deleteWhitespaceNewline:title type:0];
[weakSelf searchKeyWords:trimedString];
}];
[v_top addSubview:searchView];
[self.mainLayout addSubview:v_top];
tab_result = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
tab_result.estimatedSectionHeaderHeight = 0;
tab_result.delegate = self;
tab_result.dataSource = self;
[self.mainLayout addSubview:tab_result];
[tab_result mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->v_top.mas_bottom);
make.left.right.bottom.equalTo(self.mainLayout);
}];
noResultView = [[UIView alloc]init];
noResultView.backgroundColor = COLOR_C_FRom(0xffffff, 1.0);
[self.mainLayout addSubview:noResultView];
[noResultView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->v_top.mas_bottom);
make.left.right.bottom.equalTo(self.mainLayout);
}];
UIImageView *img_nosearch = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"搜索无结果"]];
[noResultView addSubview:img_nosearch];
[img_nosearch mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self->noResultView);
make.top.equalTo(self->noResultView.mas_top).offset(140);
}];
UILabel *lbl_title = [[UILabel alloc]init];
lbl_title.textColor = UIColorFromRGB(0x888888, 1.0);
lbl_title.text = @"暂无结果,换个词试试吧~";
lbl_title.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
[noResultView addSubview:lbl_title];
[lbl_title mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self->noResultView);
make.top.equalTo(img_nosearch.mas_bottom).offset(12);
}];
noResultView.hidden = YES;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
}
- (void)searchKeyWords:(NSString *)title
{
if (title.length <=0 ) {
[muarr_list removeAllObjects];
[tab_result reloadData];
return;
}
AMapInputTipsSearchRequest *tips = [[AMapInputTipsSearchRequest alloc] init];
tips.keywords = title;
tips.city = self.cityAddress.city;
tips.cityLimit = NO;
[self.search AMapInputTipsSearch:tips];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField.text.length <=0 ) {
[muarr_list removeAllObjects];
[tab_result reloadData];
return YES;
}
AMapInputTipsSearchRequest *tips = [[AMapInputTipsSearchRequest alloc] init];
tips.keywords = textField.text;
tips.city = self.cityAddress.city;
tips.cityLimit = NO;
[self.search AMapInputTipsSearch:tips];
return YES;
}
- (void)onInputTipsSearchDone:(AMapInputTipsSearchRequest *)request response:(AMapInputTipsSearchResponse *)response
{
//解析response获取提示词,具体解析见 Demo
if (response.tips.count>0) {
muarr_list = [response.tips mutableCopy];
[self.view bringSubviewToFront:tab_result];
noResultView.hidden = YES;
}else{
[self.view bringSubviewToFront:noResultView];
noResultView.hidden = NO;
[muarr_list removeAllObjects];
}
[tab_result reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return muarr_list.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
AMapTip *tip = muarr_list[indexPath.row];
cell.textLabel.text = tip.name;
cell.detailTextLabel.text = tip.address;
cell.detailTextLabel.textColor = UIColorFromRGB(0x999999, 1.0);
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
[searchView.YYSearch resignFirstResponder];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
AMapTip *tip = muarr_list[indexPath.row];
[[NSNotificationCenter defaultCenter]postNotificationName:@"noti_reviewCenter" object:tip];
[self dismissViewControllerAnimated:NO completion:nil];
}
@end