tableview-Data Refresh Data refreshes
- Add data
- Delete data
- Change data
Global Refresh method (most commonly used)
[self.tableView reloadData];// 屏幕上的所有可视的cell都会刷新一遍
Local Refresh Method
NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
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