У меня есть строка поиска и идентификаторы ее порядка поиска в моем табличном представлении, в этой точке у меня есть другой массив, у которого есть некоторые данные в соответствии с их идентификаторами порядка. Моя панель поиска работает правильно, фильтрованный массив работает правильно, но другой массив не работает. (идентификаторы заказов и содержание заказов имеют конфликты) Порядок заказов смещается. Как я могу соединить эти два массива? Вот мой код:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: sipCellId, for: indexPath) as! sipCell
if isSearching {
searched = filteredArray[indexPath.row]
}else{
searched = self.orderId[indexPath.row]
}
cell.orderIdLabel.text = searched
cell.detailLabel.text = self.newDatas[indexPath.row]
return cell
}
Вот мои функции панели поиска:
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if mainSearchBar.text == nil || mainSearchBar.text == "" {
isSearching = false
view.endEditing(true)
tableView.reloadData()
}else {
isSearching = true
filteredArray = orderId.filter({$0.range(of: mainSearchBar.text!, options: .caseInsensitive) != nil})
tableView.reloadData()
}
}