iOS Development UI Basics-Data Refresh

Source: Internet
Author: User

iOS Development UI Basics-Data RefreshThe data refresh of the cell contains the following aspects
    • 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 (e.g.)


Left slide appears button. png
    • Need to implement proxy methods for TableView
/** *  只要实现了这个方法,左滑出现Delete按钮的功能就有了 *  点击了“左滑出现的Delete按钮”会调用这个方法 */- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    // 删除模型    [self.wineArray removeObjectAtIndex:indexPath.row];    // 刷新    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];}/** *  修改Delete按钮文字为“删除” */- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{    return @"删除";}
Left slide appears n buttons


The left slide appears more buttons. png
    • 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 left slide cell */-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: ( Nsindexpath *) indexpath{uitableviewrowaction *action0 = [uitableviewrowaction rowactionwithstyle: Uitableviewrowactionstylenormal title:@ "concern" handler:^ (uitableviewrowaction *action, Nsindexpath *indexPath) {//retract    Left slide button appears (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;
Reprint Source: http://www.jianshu.com/p/286923700c84

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iOS Development UI Basics-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.