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];

  • 相关阅读:
    结对第一次—疫情统计可视化(原型设计)
    软工实践寒假作业(2/2)
    软工实践寒假作业(1/2)
    Luogu P3975 [TJOI2015]弦论
    【模板】后缀自动机 (SAM)
    停用FF新鲜事/FF新推荐
    模板汇总
    Luogu P4467 [SCOI2007]k短路(模板)
    【模板】 最短路
    Luogu P5960 【模板】差分约束算法
  • 原文地址:https://www.cnblogs.com/lxllanou/p/3671770.html
Copyright © 2011-2022 走看看