Ошибка IndexPath после сортировки массива

Я получаю странное поведение Каждый раз, когда я сортирую свой массив, мой tableView не соответствует моей новой сортировке.

Расположение меняется, но когда я выбираю строку, указатель указывается неверно.

func SortShoppingListItemsArrayBy_isSelected() -> Void {
    if ShoppingListsArray[currentShoppingListIndex].ItemsArray!.count > 0{
        ShoppingListsArray[currentShoppingListIndex].ItemsArray!.sort{ !$0.isSelected! && $1.isSelected! }
        ShoppingListDetailTableView.reloadData()
    }
}

Кто-нибудь может сказать мне, почему?

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if ShoppingListsArray[currentShoppingListIndex].ItemsArray!.count > 0 {
        let row = indexPath.row
        //Allow only select on checked items => unchecked must be dropped to basket
        if ShoppingListsArray[currentShoppingListIndex].ItemsArray![row].isSelected == false { return }
        ShoppingListsArray[currentShoppingListIndex].ItemsArray![row].isSelected  = ShoppingListsArray[currentShoppingListIndex].ItemsArray![row].isSelected == false ? true : false
        firebaseShoppingListItem.EditIsSelectedOnShoppingListItem(list: ShoppingListsArray[currentShoppingListIndex], shoppingListItem: ShoppingListsArray[currentShoppingListIndex].ItemsArray![row])
    }
}

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: String.ShoppingListItemTableViewCell_Identifier, for: indexPath) as! ShoppingListItemTableViewCell
        cell.selectionStyle = .none
        cell.ConfigureCell(shoppingListItem: ShoppingListsArray[currentShoppingListIndex].ItemsArray![indexPath.row])
    return cell
}

0 ответов

Другие вопросы по тегам