zoukankan      html  css  js  c++  java
  • ios学习记录 day34 UI10+ UITableView编辑

    需要手动添加删除 移动

    一.编辑过程

    1.让tableView处于编辑状态

    2.指定tableView哪些行可以编辑

    3.指定tableView编辑样式(添加,删除)

    4.编辑完成(先操作数据源,在修改UI界面)

    二.移动Move

    //移动的两个协议
    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return YES;
    }
    //上下移动的时候走 需要实现改变数据源
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
    {
        NSDictionary *dic = [_tableArr objectAtIndex:sourceIndexPath.section];
        NSMutableArray *arr = [dic objectForKey:@"stu"];
        
        //移动效果 不是交换
        //remove引用计数减1,arr没了就 所以要先retain +1
        Model *temp = [[arr objectAtIndex:sourceIndexPath.row] retain];
        [arr removeObjectAtIndex:sourceIndexPath.row];
        [arr insertObject:temp atIndex:destinationIndexPath.row];
        [temp release];
        
        //数据源修改之后必须刷新界面
        [tableView reloadData];
    }

    //不能跨区移动的协议
    -(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
    {
        if (sourceIndexPath.section == proposedDestinationIndexPath.section) {
            return proposedDestinationIndexPath;//如果section相同 移动
        }
        return sourceIndexPath;//返回原来的位置
    }

    //刷新所有的TableView的协议(编辑后刷新界面!)
            [tableView reloadData];

  • 相关阅读:
    cf 1155 d 最大区间和(变形 区间*x)
    俄罗斯方块的形状暴力
    cf 1160 E dp 组合数 思维
    cf 1110d dp(题目特殊性质)
    cf 1114d 区间dp 0,1标记左右
    poj 1426 bfs
    poj 1679 最小生成树是否唯一
    cf 1106e dp
    【PAT顶级】1002 Business (35分)(0/1背包,DP)
    【PAT顶级】1001 Battle Over Cities
  • 原文地址:https://www.cnblogs.com/lxllanou/p/3671770.html
Copyright © 2011-2022 走看看