Overriding cells in a UITableView

I have a tableView with 10 sections, and each section has 3 rows.

Is it possible to redo a section using tableViewDelegate methods

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath 
  toIndexPath:(NSIndexPath *)toIndexPath {
}

Right now, if I drag a row from one section and drop it into another section, it is added to this section. The footer view is also not selected for reordering, and it remains in the original section.

Any ideas?

thank

+3
source share
2 answers

Check out this tutorial: Add, Remove, and Reorder UITableView Rows . There is a working draft at the end of the textbook.

+4
source

Google, , . Objective-C , indexPaths moveRowAtIndex.

:

UITableViewController, :

func toggleEditing() {
    self.editing = !self.editing
}

UITableViewController (, UIViewController ( , UITableViewController), :

func toggleEditing() {
    self.editing = !self.editing
}

. tableView - UITableView.

canMoveRowAtIndexPath

override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return true 
}

moveRowAtIndexPath

override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
   var itemToMove = tableData[fromIndexPath.row]
   tableData.removeAtIndex(fromIndexPath.row)
   tableData.insert(itemToMove, atIndex: toIndexPath.row)
}
+4

Source: https://habr.com/ru/post/1790945/


All Articles