UITableView Table View Editing

Source: Internet
Author: User

Uitableviewcontroller (Table View Controller) inherits from Uiviewcontroller, with a tableviewSelf.view is not UIView but UITableView .DataSource and delegate you are self (uitableviewcontroller) by defaultonly need to establish uitableviewcontroller subclass during development  TableView Edit  TableView Edit: Cell additions, deletionsUse the scene: Delete a downloaded video and delete the contact. insert a new chat record, etc. Steps to edit 1, self let TableView in the editing state 
//editbuttonitem corresponds to the corresponding method of the internal according to the state of the click button through the setediting:animtated: method to control whether the table view into the editing stateself.navigationItem.rightBarButtonItem = Self.editbuttonitem;2, specify tableview those lines can be edited

 3. Specify TableView edit style (add, delete)
 4. Edit complete (first manipulate data source, modify UI)
//Override to support editing the table view.- (void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath {if(Editingstyle = =uitableviewcelleditingstyledelete) {        //Delete The row from the data source//1. The data of the corresponding row should be deleted first//2. Delete the corresponding row cells from the table view[Self.datasource RemoveObjectAtIndex:indexPath.row];    [TableView Deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationmiddle]; } Else if(Editingstyle = =Uitableviewcelleditingstyleinsert) {        //Create A new instance of the appropriate class, insert it into the array, and add a new row to the table view//1. Insert the corresponding object in the array now//2, create the corresponding object Indexpath//3. Insert the corresponding row according to the position of the Indexpath in the table view[Self.datasource AddObject:@"the newly inserted data"]; Nsindexpath*insertpath = [Nsindexpath indexPathForRow:self.datasource.count-1Insection:0];    [TableView Insertrowsatindexpaths:@[insertpath] withrowanimation:uitableviewrowanimationmiddle]; }   }

This method will be used when the table is dragged,

When the table is in the editing state, you can set the appropriate table to be edited with the following methods

 

UITableView Table View Editing

Related Article

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.