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

  • 相关阅读:
    js获取url参数值[转]
    jQuery.validate 中文API【转】
    tinyMCE使用详解
    使IE6下PNG背景透明的七种方法任你选
    MVC3 上传文件【转】
    兼容google浏览器的CSS代码
    MVC3 输出HTML标签
    正则表达式 非常实用
    silverlight 压缩算法
    silverlight 4调试离线应用
  • 原文地址:https://www.cnblogs.com/lxllanou/p/3671770.html
Copyright © 2011-2022 走看看