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]];//将数据插入此空缺
    }

    其他未做修改。

    求指点。

  • 相关阅读:
    javascript package的一种简单"优雅"实现
    高效、快速、专业的外科手术团队
    贝塞尔曲线
    经典格斗游戏《街头霸王》的Javascript实现
    该死的痘痘
    同步/异步与阻塞/非阻塞的区别
    Shell echo用法
    凹凸Linux面试题
    VMware Workstation 9下安装Fedora 18教程(转)
    Linux中locale 详解(转)
  • 原文地址:https://www.cnblogs.com/maxfong/p/2493745.html
Copyright © 2011-2022 走看看