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

  • 相关阅读:
    tabbar 旋转指定的页面
    GDAL中文路径不能打开&Shp文件字段属性值中文乱码
    Project : error PRJ0019: 工具从"Moc'ing xxx.h..."
    详解Android中的屏幕方向
    qt中获取文件路径和文件名
    vs2005下Qt项目中修改exe图标的方法
    Qt & C/C++统计运行时间
    Qt 中Treewidget添加右键菜单
    QT 中文乱码解决方案
    Qt多线程应用QRunnable显示进度条示例
  • 原文地址:https://www.cnblogs.com/lxllanou/p/3671770.html
Copyright © 2011-2022 走看看