LoginSignup
3
2

More than 5 years have passed since last update.

tableViewの並び替えで他のSectionには行かせないようにする

Last updated at Posted at 2018-08-24

TableViewで最初の3つのセルは並び替え不可、それ以降は並び替えできるようにしたく、Sectionを分けたが、Sectionを超えて並び替えできてしまった。

ViewController.swift
override func tableView(_ tableView:UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
    if (proposedDestinationIndexPath.section != sourceIndexPath.section) {
        return sourceIndexPath
    }
    return proposedDestinationIndexPath;
}

以上のようにすればSectionを超えた場合はうごかないように

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2