Ios-ui Control UITableView (quad)-cell data refresh

Source: Internet
Author: User

tableview-Data Refresh Data refreshes
    • Add data
    • Delete data
    • Change data
Global Refresh method (most commonly used)
[self.tableView reloadData];// 屏幕上的所有可视的cell都会刷新一遍
Local Refresh Method
    • Add data
NSArray *indexPaths = @[                        [NSIndexPath indexPathForRow:0 inSection:0],                        [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
    • Delete data
NSArray *indexPaths = @[                        [NSIndexPath indexPathForRow:0 inSection:0],                        [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
    • 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 function of the Delete button on the left slide has a * Click 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 proxy methods for TableView
/** * As long as the implementation of this method, the left slide appears the function of the button (once the left slide 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 the left slide cell */-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: (Nsindexpath *) indexpath{uitableviewrowaction *action0 = [uitableviewrowaction rowactionwithstyle: Uitableviewrowactionstylenormal title:@ "Attention" handler:^ (uitableviewrowaction *action, nsindexpath *indexpath) { NSLog (@ "click on"); //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;

Ios-ui Control UITableView (quad)-cell data refresh

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.