实现了一个类似于京东的地址填写的东西,首先是省市区地址选择,自定义pickerview,pickerview最麻烦的就是没有默认选择的问题,所以校验的东西比较多,因为区分为省市区三个competent,那么就需要重复判断
if ([NSString isNull:_selectProvicename]) {
NSString *proString = [[_provicesArray objectAtIndex:0] objectForKey:@"areaName"];
_selectProvicename = proString;
if ([NSString isNull:_selectCityname]) {
_selectCityname = [[_citysArray objectAtIndex:0] objectForKey:@"areaName"];;
}
if ([NSString isNull:_selectCountyname]) {
_selectCountyname = [[_countiesArray objectAtIndex:0] objectForKey:@"areaName"];
}
}
if ([NSString isNull:_selectCityname]) {
NSString *cityname = [[_citysArray objectAtIndex:0] objectForKey:@"areaName"];
_selectCityname = cityname;
if ([NSString isNull:_selectCountyname]) {
_selectCountyname = [[_countiesArray objectAtIndex:0] objectForKey:@"areaName"];
}
}
if ([NSString isNull:_selectCountyname]) {
_selectCountyname = [[_countiesArray objectAtIndex:0] objectForKey:@"areaName"];
}
if (self.bringSelectCityBlcok) {
self.bringSelectCityBlcok(_selectProvicename, _selectCityname, _selectCountyname);
}
这个就比较麻烦,有人有比较好的解决方案的话请给我建议。
其次是实现百度的poisearch
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if (textField.tag==102) {
_poisearch = [[BMKPoiSearch alloc] init];
_poisearch.delegate = self;
self.tableView.frame = CGRectMake(0.0, -45-10, SCREEN_WIDTH, self.tableView.height);
}
return YES;
}
- (void)textchangeShowSearch:(UITextField *)tf{
if (tf.text.length>0) {
BMKCitySearchOption *citySearchOption = [[BMKCitySearchOption alloc]init];
_searchString = tf.text;
citySearchOption.pageIndex = 0;
citySearchOption.pageCapacity = 10;
citySearchOption.city = self.addressModel.area;
citySearchOption.keyword = tf.text;
BOOL flag = [_poisearch poiSearchInCity:citySearchOption];
if(flag)
{
NSLog(@"城市内检索发送成功");
}
else
{
NSLog(@"城市内检索发送失败");
}
[self.tableView addSubview:self.addressShowTableView];
[ self.addressShowTableView setHeight:self.view.height-self.keyboardHeight-(10+45*2)];
}
}
#pragma mark searchDelegate
#pragma mark implement BMKSearchDelegate
- (void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult*)result errorCode:(BMKSearchErrorCode)error
{
if (error == BMK_SEARCH_NO_ERROR) {
self.poiResult = result;
// 清楚屏幕中所有的annotation
[self.addressShowTableView reloadData];
} else if (error == BMK_SEARCH_AMBIGUOUS_ROURE_ADDR){
NSLog(@"起始点有歧义");
} else {
// 各种情况的判断。。。
}
}
这里边就需要考虑搜索结果出现后关于列表的展示以及view位置的更新的问题,百度地图还有一个热词搜索,也可以配合使用会比较完美,就是需要处理其他逻辑