-1

this code was fully working prior updating to ios 11 and swift 4, I don't know what's happening I have also attached a video showing the issue.

I can't move the rows anymore. Any advise? Thanks.

override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    return true
}

//Do the Move action
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

    let moveMainArray:String = mainArrayTableName[sourceIndexPath.row]
    mainArrayTableName.remove(at: sourceIndexPath.row)
    mainArrayTableName.insert(moveMainArray, at: destinationIndexPath.row)
    print(mainArrayTableName[destinationIndexPath.row])

    let moveFirstName:String = firstName[sourceIndexPath.row]
    firstName.remove(at: sourceIndexPath.row)
    firstName.insert(moveFirstName, at: destinationIndexPath.row)
    print(firstName[destinationIndexPath.row])

    let moveLastName:String = lastName[sourceIndexPath.row]
    lastName.remove(at: sourceIndexPath.row)
    lastName.insert(moveLastName, at: destinationIndexPath.row)
    print(lastName[destinationIndexPath.row])

    let moveTotalAmount:String = totalAmount[sourceIndexPath.row]
    totalAmount.remove(at: sourceIndexPath.row)
    totalAmount.insert(moveTotalAmount, at: destinationIndexPath.row)
    print(totalAmount[destinationIndexPath.row])

    let moveLastAmount:String = lastAmount[sourceIndexPath.row]
    lastAmount.remove(at: sourceIndexPath.row)
    lastAmount.insert(moveLastAmount, at: destinationIndexPath.row)
    print(lastAmount[destinationIndexPath.row])

    let moveAddress:String = address[sourceIndexPath.row]
    address.remove(at: sourceIndexPath.row)
    address.insert(moveAddress, at: destinationIndexPath.row)
    print(address[destinationIndexPath.row])

    let movePhoneNbr:String = phoneNbr[sourceIndexPath.row]
    phoneNbr.remove(at: sourceIndexPath.row)
    phoneNbr.insert(movePhoneNbr, at: destinationIndexPath.row)
    print(phoneNbr[destinationIndexPath.row])

    let moveLastPayment:String = lastPaymentDate[sourceIndexPath.row]
    lastPaymentDate.remove(at: sourceIndexPath.row)
    lastPaymentDate.insert(moveLastPayment, at: destinationIndexPath.row)
    print(lastPaymentDate[destinationIndexPath.row])

    let moveNextPayment:String = nextPaymentDate[sourceIndexPath.row]
    nextPaymentDate.remove(at: sourceIndexPath.row)
    nextPaymentDate.insert(moveNextPayment, at: destinationIndexPath.row)
    print(nextPaymentDate[destinationIndexPath.row])

    let moveRemaining:String = remainingAmount[sourceIndexPath.row]
    remainingAmount.remove(at: sourceIndexPath.row)
    remainingAmount.insert(moveRemaining, at: destinationIndexPath.row)
    print(remainingAmount[destinationIndexPath.row])

    print(userID[destinationIndexPath.row])  
}

Link for the Video: https://www.dropbox.com/s/0c0tlldbehrpslo/ScreenRecording_04-10-2018%2021-17-03.MP4?dl=0

Thanks again

4 Answers4

1

Try tableView.setEditing(true, animated: true). It will give you both (reorder and delete) controls as given in image.

enter image description here

Chanchal Chauhan
  • 1,530
  • 13
  • 25
  • I will try this, but the issue is that i'm having the edit and delete icons. You can check the video link I have attached. The Issue is that the rows are not moving. – Khajak Kirikian Apr 11 '18 at 20:15
  • I have added that line of code under: override func tableView(_ tableView: UITableView, canMoveRowAt: indexPath: IndexPath) -> Bool { } --------But no luck-------- – Khajak Kirikian Apr 12 '18 at 05:41
  • Are you getting callback in `tableView(_ tableView: UITableView, canMoveRowAt: indexPath: IndexPath)` ? In my case when I add `tableView.isEditing = true` in `viewDidLoad()` It worked. – Chanchal Chauhan Apr 12 '18 at 06:12
  • Were you facing the same issue? And yes it's going through that Method, I have even removed the above code and kept: let moveMainArray:String = mainArrayTableName[sourceIndexPath.row] mainArrayTableName.remove(at: sourceIndexPath.row) mainArrayTableName.insert(moveMainArray, at: destinationIndexPath.row) print(mainArrayTableName[destinationIndexPath.row]) But still nothing. I will try to add tableView.isEditing = true in ViewDidLoad() and update you. Thanks! – Khajak Kirikian Apr 12 '18 at 15:02
  • The tableView.isEditing = true, will only activate the edit mode on launch. Tested. But my issue still there, it's like the rows are locked and I can't move them. So Weird – Khajak Kirikian Apr 16 '18 at 01:17
  • Can you share your code. Because in my case its moving perfectly. – Chanchal Chauhan Apr 16 '18 at 05:36
  • Well The code is still the above, no changes I have removed the UINavigationController View, and it worked good. – Khajak Kirikian Apr 22 '18 at 21:55
0

If by any chance you have this in your code:

navigationController?.hidesBarsOnSwipe = true

Then set it to false, to give priority to tableview's scrollview.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Chiman Song
  • 141
  • 10
0

The issue is due to the Navigation Controller "hide bars" "on swipe" option. If you deselect it, the issue is fixed. enter image description here

-1

The Issue isn't in the code itself. For some reason, I had a navigation Controller and that was causing the issue. Once that's removed, the re-ordering is now working perfect with no issues. Thanks for the help.