Ios-uitableview Primer (3)

Source: Internet
Author: User

UITableView itself with the (add, delete) editing function:

1. As long as the edit code that calls UITableView goes into edit state:

[Self.tableview setediting:!self.tableview.editing Animated:yes];

2. The UITableView that enters the edit state will invoke the proxy's

-(uitableviewcelleditingstyle) TableView: (uitableview *) TableView Editingstyleforrowatindexpath: To determine whether to increase or remove the method.

Uitableviewcelleditingstyle is an enumeration value, such as Uitableviewcelleditingstyledelete,uitableviewcelleditingstyleinsert

The overall code is as follows:

#pragma Mark Click Edit Delete-(ibaction) Trashclick: (ID) sender {self.tableview.tag=edit_move; [Self.tableview setediting:!self.tableview.editing animated:yes];} #pragma mark-tableviewdatasource#pragma mark the method that is called when the delete State is clicked when the edit state is present #pragma mark when adding a button to increase the status of a click on the option to save the call Method-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath        :(Nsindexpath *) indexpath{if (tableview.tag==20) {[Self.arr removeObjectAtIndex:indexPath.row];    [TableView Deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationleft];        } else {[Self.arr insertobject:@ "New row ..." atindex:indexpath.row+1];        Nsindexpath *indexnew=[nsindexpath indexpathforrow:indexpath.row+1 insection:0];    [TableView insertrowsatindexpaths:@[indexnew] withrowanimation:uitableviewrowanimationright]; }} #pragma mark clicks on edit to delete or Add button-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView EditingstyleforrOwatindexpath: (Nsindexpath *) indexpath{if (tableview.tag==20) {return uitableviewcelleditingstyledelete;    } else {return uitableviewcelleditingstyleinsert; }} #pragma mark moves the item so that it can save the editing order after editing the mode-(void) TableView: (UITableView *) TableView Moverowatindexpath: (Nsindexpath *)    Sourceindexpath Toindexpath: (Nsindexpath *) destinationindexpath{nsstring *currstr=self.arr[sourceindexpath.row];    [Self.arr RemoveObjectAtIndex:sourceIndexPath.row];    [Self.arr insertobject:currstr AtIndex:destinationIndexPath.row]; [TableView Reloaddata];}    #pragma mark Click Edit Add-(ibaction) AddClick: (ID) sender {self.tableview.tag=edit_add; [Self.tableview setediting:!self.tableview.editing animated:yes];}


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.