UITableView edit mode

Source: Internet
Author: User

UITableView has two modes, normal mode and edit mode. The cell can be sorted, deleted, inserted, and so on in edit mode.

    1. How to enter edit mode
      calls the setediting (Editing:bool, Animated:bool) method of TableView.

      • What happens after you enter edit mode

        • Send to each cell setediting:animated: method

        • Cell changes after entering edit mode


          Normal Mode The bounds of the cell's contentview is the bounds of the cell.
          In edit mode, the cell has three parts, the left editing control, the middle Contentview, the right reordering control. The position and size of the Contentview have changed.
          So in general, add what you need to show to the Contentview, not the cell. Documentation is also described.

          The content view of a UITableViewCell object is the default Superview for content Displa Yed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they would be Positioned appropriately as the cell transitions into and out of editing mode

  • Delete mode

    • Specify mode for delete mode

        func tableView (Tableview:uitableview, Editingstyleforrowatindexpath Indexpath:nsindexpath), Uitableviewcelleditingstyle {return. Delete}  
    • Custom Delete prompt

        func tableView (Tableview:uitableview, Titlefordeleteconfirmationbuttonforrowatindexpath indexpath:nsindexpath)-String? {return "I delete"}  

      At this point, the cell to the right of a more part, called Uitableviewcelldeleteconfirmtionview , different deletion prompts, the length is not the same.

  • Insert mode

    • Just set the style to insert.

      func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {return .Insert}
    • Show the Sort button on the right

      func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {//do something    }

      This is a good way to do it, even if you don't do anything.

  • Show multi-Select button

        tableView?.allowsMultipleSelectionDuringEditing = true    tableView?.tintColor = UIColor.blackColor()

  • Swipe to delete

    • Implementing the appropriate Proxy method

      func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {   }

      Methods cannot be called in this method setEditing(_:animated:)

    • tableView(_:editingStyleForRowAt:)Method must return a delete

UITableView edit mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.