IOS development UI basics-data refresh and iosui basics --

Source: Internet
Author: User

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
  • 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 (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.

Related Article

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.