在搜索栏中执行搜索时如何获取表视图的原始索引?

how to get original index of tableview when search is perform in searchbar?

我正在做一个数据来自服务器的项目。

数据包含(纬度、经度、地区和街道名称)。我将每个字段保存在单独的数组中,并仅在 table 视图中显示与该位置相关的地区和街道名称。

当用户单击 table-view 的特定行时,会出现另一个屏幕,并且 tableviewcell 的特定索引的位置会显示在地图上 viva 特定的经纬度。

当我在 table 视图上实现搜索栏以搜索地区名称时,我如何才能获得搜索地区的准确经度和纬度?

您可以从区域数组中获取区域索引,并从同一索引处的经度数组中获取经度。

Swift:

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 {
    txtForSearch.placeholder=@"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];
}