Iostableview Local all refresh and delete edit operations

Source: Internet
Author: User

  • Local Refresh Method

    1. Add data

      NSArray *indexPaths = @[                       [NSIndexPath indexPathForRow:0 inSection:0],                       [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
    2. Delete data

      nsarray * indexpaths = @[[nsindexpath indexpathforrow:0 I Nsection:0], [nsindexpath Indexpathforrow:1 insection:0]]; [self.tableview deleterowsatindexpaths:indexpaths Withrowanimation:uitableviewrowanimationmiddle];       
    3. Update data (without adding and deleting data, just modifying existing data)

      NSArray *indexPaths = @[                     [NSIndexPath indexPathForRow:0 inSection:0],                     [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView relaodRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
  • Left slide appears delete button

    • Need to implement proxy methods for TableView

        As long as this method is implemented, the left slide appears with the Delete button function.Clicking on the "left slide" Delete button will call this method-(void) TableView: (uitableview *) TableView Commiteditingstyle: ( Uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (NSIndexPath *) IndexPath { //Delete model [self.wineArray Removeobjectatindex:indexpath.row]; //refresh [TableView Deleterowsatindexpaths:@[indexpath] Withrowanimation:uitableviewrowanimationleft"; } //Modify the Delete button text to "delete"-(nsstring *) TableView: (uitableview *) TableView Titlefordeleteconfirmationbuttonforrowatindexpath: ( nsindexpath *) Indexpath {return  @ "Delete"; }
  • Left slide appears n buttons

    • Need to implement TableView proxy method as long as the implementation of this method, the left Slide button function will be there (once the left slip appears n buttons, tableView into the editing mode, tableview.editing = YES)

      - (void) TableView: (UITableView *) TableView Commiteditingstyle: (Uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath {}What button appears when left slide cell-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) Indexpath {Uitableviewrowaction *action0 = [Uitableviewrowaction Rowactionwithstyle:Uitableviewrowactionstylenormal title:@ "Follow" handler:^ (Uitableviewrowaction *action,Nsindexpath *indexpath) {nslog (@ "clicked attention"); //retract left Slide button (Exit edit mode) Tableview.editing = NO; }]; uitableviewrowaction *action1 = [UITableViewRowAction Rowactionwithstyle:uitableviewrowactionstyledefault title: @ "delete" handler:^ (uitableviewrowaction *action, nsindexpath *indexpath) {[self.wineArray Removeobjectatindex:indexpath.row]; [TableView Deleterowsatindexpaths:@[indexpath] Withrowanimation: Uitableviewrowanimationautomatic]; }]; return @[action1, Action0];}          
  • Enter edit mode

// self.tabelView.editing = YES;[self.tableView setEditing:YES animated:YES];// 默认情况下,进入编辑模式时,左边会出现一排红色的“减号”按钮
    • Multi-Select in edit mode
// 编辑模式的时候可以多选self.tableView.allowsMultipleSelectionDuringEditing = YES;// 进入编辑模式[self.tableView setEditing:YES animated:YES];// 获得选中的所有行self.tableView.indexPathsForSelectedRows;

Iostableview Local all refresh and delete edit operations

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.