0

我有一个奇怪的行为。每次我对数组进行排序时,我的 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
}
4

0 回答 0