zoukankan      html  css  js  c++  java
  • FirstApp,iphone开发学习总结11,表操作(移动、删除)

    nav添加左按钮:

    - (void)viewDidLoad
    {
    //...    
        UIBarButtonItem *tableEditBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(toggleEdit:)];
        [[self navigationItem] setLeftBarButtonItem:tableEditBtn];
        [tableEditBtn release];
    }

    edit按钮的实现:

    - (void)toggleEdit:(id)sender
    {
        if ([self isEditing]) {
            [self setEditing:NO animated:YES];
        }else{
            [self setEditing:YES animated:YES];//设置编辑状态
        }
    }

    表删除:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            [data removeObjectAtIndex:[indexPath row]];//先移除数据,再移除表里的显示
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];        
        }
    }

    表移动:

    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
    {
        NSArray *moveRow = [data objectAtIndex:[sourceIndexPath row]];//保存移动的行
        [data removeObjectAtIndex:[sourceIndexPath row]];//将移动行数据清除,此时移动至的行空缺
        [data insertObject:moveRow atIndex:[destinationIndexPath row]];//将数据插入此空缺
    }

    其他未做修改。

    求指点。

  • 相关阅读:
    PHP独立环境安装与文件配置
    变量常量区别及用法
    PHP初步了解
    js dom操作基本单词和格式
    PHP 类的继承 访问修饰符 重写
    PHP面向对象基本概念 类与对象 静态属性 构造/析构方法
    人员定位系统项目整理
    json
    租房子ajax
    省市区三级联动用ajax实现
  • 原文地址:https://www.cnblogs.com/maxfong/p/2493745.html
Copyright © 2011-2022 走看看