如何在搜索栏中执行搜索时获取tableview的原始索引?
我正在从数据来自服务器的项目工作。数据包含(纬度,经度,地区和街道名称)。我将每个字段保存在单独的数组中,只是在tableview上显示与该位置相关的区域和街道名称。如何在搜索栏中执行搜索时获取tableview的原始索引?
当用户点击table-view的特定行时,出现另一个屏幕,tableviewcell的特定索引的位置显示在地图上viva特定的lat,lon。
当我在tableview上实现搜索栏来搜索地区名称的话我怎么才能得到精确的搜索区域的经度和纬度?
您可以从分区数组中获取分区的索引,并从相同索引处的经度数组获取经度。
斯威夫特:
let index = find(district,districtArray)!
let longitude = longitudeArray[index]
let latitude = latitudeArray[index]
的Objective-C:
int index = [districtArray indexOfObject:district];
double latitude = latitudeArray[index];
double longitude = longitudeArray[index];
我认为在所有的数组中存在的数据,但如果有一个机会,一些阵列在一些指数将是空做错误检查以及。
- (void) Search_TF_Call {
[email protected]"Type a name";
txtForSearch.returnKeyType = UIReturnKeyDone;
txtForSearch.autocorrectionType = UITextAutocorrectionTypeNo;
[txtForSearch addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
- (void) textFieldDidChange:(UITextField *)txtFld {
NSMutableArray *nameArray = [[NSMutableArray alloc] initWithArray:tempContact];
NSString *match = txtFld.text;
NSMutableArray *listFiles = [[NSMutableArray alloc] init];
NSArray *terms = [match componentsSeparatedByCharactersInSet:[NSCharacterSet nonBaseCharacterSet]];
for (NSString *term in terms) {
if([term length] == 0) { continue; }
NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[cd] %@", term];
[listFiles addObject:p];
}
NSPredicate *filter = [NSCompoundPredicate andPredicateWithSubpredicates:listFiles];
listFiles = [NSMutableArray arrayWithArray:[nameArray filteredArrayUsingPredicate:filter]];
if (txtFld.text.length > 0) {
sortedArrayForTempContact = listFiles;
}
else {
sortedArrayForTempContact = tempContact;
}
[tblView reloadData];
}
nameArray和sortedArrayForTempContact在.h文件中声明 –
我有三个数组,所有这三个数组都是20个元素,索引0处的元素在另一个数组中具有相同索引处的相关数据。问题是,当我在一个数组上执行搜索viva搜索栏时,那么我如何从其他两个数组获得相关数据。例如,我有分区数组,另外两个是经度和纬度数组。 – user2293751
我有三个阵列,所有三个都是20层的元件和元件在索引0处已经培训相关的数据在相同的指数。问题另一个数组是,当我执行搜索VIVA搜索栏在一个阵列上,然后我如何获得来自其他两个阵列的相关数据。例如,我有分区数组,另外两个是经度和纬度数组。 – user2293751