eg:数据库表对象

@interface Meditation :
NSManagedObject

@property (nonatomic,
retain) NSString * order;//用来排序的属性值。用0、1、2、3...排序

@end

//在这种方法里操作

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

Meditation *sourceMeditation=[self.dataSource
objectAtIndex:sourceIndexPath.row];

sourceMeditation.order =[NSString
stringWithFormat:@"%i",destinationIndexPath.row];

[sourceMeditation.managedObjectContext
save:nil];

//两种情况一种是上移,第二种是下移

1.sourceIndexPath.row>destinationIndexPath.row

2.sourceIndexPath.row>destinationIndexPath.row

if (sourceIndexPath.row < destinationIndexPath.row)

{

for (NSInteger i = sourceIndexPath.row+1; i <= destinationIndexPath.row; i ++)

{

Meditation *m = [self.dataSource
objectAtIndex:i];

m.order =[NSString
stringWithFormat:@"%i",[m.attribute6
integerValue]-1];

[sourceMeditation.managedObjectContext
save:nil];

}

}else

{

for (NSInteger i = sourceIndexPath.row-1; i >= destinationIndexPath.row; i--)

{

Meditation *m = [self.dataSource
objectAtIndex:i];

m.order =[NSString
stringWithFormat:@"%i",[m.attribute6
integerValue]+1];

[sourceMeditation.managedObjectContext
save:nil];

}

}

}

//当对象被删除的时候(依照order的升序排列)。把删除数据以下的数据对象的order属性值-1

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

if (editingStyle ==
UITableViewCellEditingStyleDelete) {

for (int i=indexPath.row; i<self.dataSource.count; i++) {

Meditation *m = [self.dataSource
objectAtIndex:i];

m.order =[NSString
stringWithFormat:@"%i",[m.attribute6
integerValue]-1];

[appDelegate saveContext];

}

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

一个数据表对象(NSManagedObject)加入排序的更多相关文章

  1. ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法

    ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块  --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...

  2. Oracle 11g系列:数据表对象

    Oracle数据库的下一层逻辑结构并非数据表,而是表空间.每个数据表都属于唯一的表空间. 1.Oracle表空间 与数据表相同,Oracle表空间是一个逻辑对象,而非物理对象,是数据库的组成部分.当使 ...

  3. 【SQL Sever】将SQL Sever中的一个数据表的数据导出为insert语句

    例如:这SQL   Sever中的一张数据表,想要将这张数据表中的数据  转化成一个一个的insert语句存储在txt的文档中,那么不论走到那里这个insert语句一执行,我们就能将这个数据表中的数据 ...

  4. oracle表空间查询维护命令大全之中的一个(数据表空间)史上最全

          表空间是数据库的逻辑划分,一个表空间仅仅能属于一个数据库. 全部的数据库对象都存放在建立指定的表空间中.但主要存放的是表, 所以称作表空间.在oracle 数据库中至少存在一个表空间.即S ...

  5. 使用Mybatis Generator 生产 AS400中的数据表对象

    第一次使用Mybatis,由于公司核心服务器是AS400,参考了网络各个大大的教程后,发现无法使用Mybatis Generator自动生成AS400中的表对象 参考URL: http://www.c ...

  6. 吴裕雄--天生自然ORACLE数据库学习笔记:数据表对象

    create table students( stuno ) not null, --学号 stuname ), --姓名 sex ), --性别 age int, --年龄 departno ) n ...

  7. PHP array_multisort() 函数详解 及 二维数组排序(模拟数据表记录按字段排序)

    一.先看最简单的情况. 有两个数组: $arr1 = array(1, 9, 5); $arr2 = array(6, 2, 4); array_multisort($arr1, $arr2); pr ...

  8. oracle恢复一个数据表的方法

    今天提交给客户方一个sql脚本去跟新历史数据,结果客户那边的部署人员犯了一个错误,直接拿系统账号去部署,结果第一段代码没有执行成功,结果第二段代码却执行成功了,并且已经提交了的,....由于事前没有备 ...

  9. 一个数据表通过另一个表更新数据(在UPDAT语句中使用FROM子句)

    在sql server中,update可以根据一个表的信息去更新另一个表的信息. 首先看一下语法: update A SET 字段1=B表字段表达式, 字段2=B表字段表达式   from B WHE ...

随机推荐

  1. 区间第K大

    protected static int partitions(List<KDNode> data,int left,int right,int k,int pos){ int l = l ...

  2. 邮箱password复位图

    blog宗旨:用图说话 辅助文字说明: 长处:用户系统完毕接口部分.界面留给业务自行设计. 缺点:邮箱发送邮件定制模板,没有完毕松耦合. 改进点:邮箱的准备发送邮件模板. 版权声明:本文博客原创文章, ...

  3. iframe页面控制父页面跳转

    <script> window.onload=function(){   window.location.href="http://www.baidu.com";    ...

  4. iOS_11_tableViewCell使用alertView变更数据

    最后效果图: Girl.h // // Girl.h // 11_tableView的使用_红楼梦 // // Created by beyond on 14-7-26. // Copyright ( ...

  5. Zygote过程【3】——SystemServer诞生

    欢迎转载.转载请注明:http://blog.csdn.net/zhgxhuaa 在ZygoteInit的main()方法中做了几件大事.当中一件便是启动Systemserver进程.代码例如以下: ...

  6. 微信电脑版(Mac和Windows)安装

    内容简介 1.微信Windows版 2.微信Mac版 3.总结优势 微信电脑版 众所周知,腾讯公司(马化腾先生执掌的巨头公司)开发的超成功App:微信.一经推出便引发业界轰动,使用人数更是直逼QQ. ...

  7. 并发编程实践三:Condition

    Condition实例始终被绑定到一个锁(Lock)上.Lock替代了Java的synchronized方法,而Condition则替代了Object的监视器方法,包含wait.notify和noti ...

  8. c# winform 中的 工具栏自动隐藏 splitter用法 带源码

    c# winform 中的 工具栏自动隐藏 splitter用法 带源码 代码下载地址 http://download.csdn.net/detail/simadi/7649313

  9. LINQ之路(1):LINQ基础

    本文将从什么是LINQ(What).为什么使用LINQ(Why)以及如何使用LINQ(How)三个方面来进行说明. 1.什么是LINQ LINQ(Language Integrated Query)是 ...

  10. 第一章 工欲善其事 其利润—Android SDK工具(2)

    1.2设备管理工具-调试桥(ADB) 1.2.1ADB简单介绍 ADB全称是Android Debug Bridge,是Android SDK里自带的一个工具,用这个工具能够直接操作管理Android ...