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
  • 相关阅读:
    谷歌开源计划
    windows XP/vista/win 7 开机登录密码破解大全
    QQ好友空间加密没有密码但我们又很想看怎么办?(QQ空间瞬间破解+相册破解)
    VMware Workstation 7.1.4385536官方正式版+完美汉化包+注册码
    win7/xp笔记本建立wifi热点 用手机连接上网
    Cisco路由器OSPF协议经典学习笔记
    宽带连接错误的处理办法691、623、678、645、720、721、718、734、769、619、676、815
    CCNA的综合实验2
    交换机故障的一般分类和排障步骤
    cisco_iso命名规则
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/7102550.html
Copyright © 2011-2022 走看看