Edit UITableView table view and uitableview

Source: Internet
Author: User

Edit UITableView table view and uitableview
UITableViewController (Table view Controller) is inherited from UIViewController and comes with a tableViewself. view instead of UIView, but UITableViewdatasource and delegate. By default, you only need to create a UITableViewController subclass during the development of self (UITableViewController ).Edit tableView TableView Editing: cell addition and deletion scenarios: delete a downloaded video and contacts. Insert a new chat recordEdit procedure1. self: Make tableView editable
// The corresponding method corresponding to editButtonItem uses setEditing: animtated: method to control whether the table view enters the editing status self based on the status of the clicked button. navigationItem. rightBarButtonItem = self. editButtonItem; 2. Specify the rows in tableView that can be edited.

 

3. Specify the tableView editing style (add or delete)
4. Edit (operate the data source first and modify the 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. You should first Delete the data of the corresponding row // 2, and then Delete the cells of the corresponding row from the table view [self. datasource removeObjectAtIndex: indexPath. row]; [tableView deleteRowsAtIndexPaths: @ [indexPath] withRowAnimation: Paths];} 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 // 2. Create the corresponding object indexPath // 3. According to the position of indexPath In the table view insert the corresponding row [self. datasource addObject: @ "newly inserted data"]; NSIndexPath * insertPath = [NSIndexPath indexPathForRow: self. datasource. count-1 inSection: 0]; [tableView insertRowsAtIndexPaths: @ [insertPath] withRowAnimation: UITableViewRowAnimationMiddle];}

This method is used when the table is dragged,

 

 

 

When the table is edited, you can use the following method to set whether the corresponding table is edited or not.

 

 

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.