IOS development UI basics-data refresh and iosui basics --
IOS development UI basics-data refresh cell data refresh includes the following aspects
- Add data
- Delete data
- Change Data
Global refresh method (most common)
[Self. tableView reloadData]; // refresh all visible cells on the screen
Partial 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 (not adding or deleting data, but modifying existing data)
NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] ];[self.tableView relaodRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
Slide left to display the delete button (for example)
Click Export .png on the left
- Proxy method to implement tableView
/*** As long as this method is implemented, when the Delete button appears on the left slide, * clicking the Delete button appears on the left slide 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 ";}
Slide left to show N buttons
More buttons are displayed on the left. PNG
- Proxy method to implement tableView
/*** As long as this method is implemented, the button function appears on the left slide (once N buttons appear on the left slide, tableView enters the editing mode, tableView. editing = YES) */-(void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath {}/*** button displayed when sliding cell left */-(NSArray *) tableView :( UITableView *) tableView editActionsForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewRowAction * action0 = [UITableViewRowAction rowActionWithStyle: UITableViewRowActionStyleNormal title: @ "follow" handler: ^ (UITableViewRowAction * action, NSIndexPath * indexPath) {// remove the button that appears on the left slide (exit edit mode) tableView. editing = NO;}]; UITableViewRowAction * action1 = [UITableViewRowAction rowActionWithStyle: deleting 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]; // by default, a red "minus sign" button will appear on the left when you enter the editing mode.
Select multiple in edit mode
// You can select self for the editing mode. tableView. allowsMultipleSelectionDuringEditing = YES; // enter the editing mode [self. tableView setEditing: YES animated: YES]; // obtain all selected rows self. tableView. indexPathsForSelectedRows;
Reprinted Source: http://www.jianshu.com/p/286923700c84
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.