zoukankan      html  css  js  c++  java
  • IOS开发UI基础--数据刷新

    IOS开发UI基础--数据刷新

    cell的数据刷新包括下面几个方面
    • 加入数据
    • 删除数据
    • 更改数据

    全局刷新方法(最经常使用)

    [self.tableView reloadData];
    // 屏幕上的全部可视的cell都会刷新一遍

    局部刷新方法

    • 加入数据
    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];
    • 更新数据(没有加入和删除数据,不过改动已经存在的数据)
    NSArray *indexPaths = @[
                            [NSIndexPath indexPathForRow:0 inSection:0],
                            [NSIndexPath indexPathForRow:1 inSection:0]
                            ];
    [self.tableView relaodRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];

    左滑出现删除button(例如以下图)


    左滑出现button.png
    • 须要实现tableView的代理方法
    /**
     *  仅仅要实现了这种方法,左滑出现Deletebutton的功能就有了
     *  点击了“左滑出现的Deletebutton”会调用这种方法
     */
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // 删除模型
        [self.wineArray removeObjectAtIndex:indexPath.row];
    
        // 刷新
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
    
    /**
     *  改动Deletebutton文字为“删除”
     */
    - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return @"删除";
    }

    左滑出现N个button


    左滑出现很多其它button.png
    • 须要实现tableView的代理方法
    /**
     *  仅仅要实现了这种方法,左滑出现button的功能就有了
     (一旦左滑出现了N个button,tableView就进入了编辑模式, tableView.editing = YES)
     */
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    }
    
    /**
     *  左滑cell时出现什么button
     */
    - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"关注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
    
            // 收回左滑出现的button(退出编辑模式)
            tableView.editing = NO;
        }];
    
        UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            [self.wineArray removeObjectAtIndex:indexPath.row];
            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        }];
    
        return @[action1, action0];
    }

    进入编辑模式

    // self.tabelView.editing = YES;
    [self.tableView setEditing:YES animated:YES];
    // 默认情况下,进入编辑模式时,左边会出现一排红色的“减号”button

    在编辑模式中多选

    // 编辑模式的时候能够多选
    self.tableView.allowsMultipleSelectionDuringEditing = YES;
    // 进入编辑模式
    [self.tableView setEditing:YES animated:YES];
    
    // 获得选中的全部行
    self.tableView.indexPathsForSelectedRows;
    转载出处:http://www.jianshu.com/p/286923700c84
  • 相关阅读:
    perl dbi 控制事务
    READ-COMMITTED 不能进行可重复读和防止幻读
    REPEATABLE-READ 预读
    如何规划农商行商业智能系统中的决策分析系统?
    如何规划农商行商业智能系统中的决策分析系统?
    【MySQL】gap lock 浅析
    REPEATABLE-READ和READ-COMMITTED幻读
    ORA-01555: snapshot too old
    CXF动态客户端调用webservice实例
    mysql 区间锁
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/7102550.html
Copyright © 2011-2022 走看看