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. [JSP][JSTL]页面调用函数--它${fn:}内置函数、是推断字符串是空的、更换车厢

    页面中调用函数--之${fn:}内置函数 函数描写叙述 fn:contains(string, substring) 假设參数string中包括參数substring,返回true fn:contai ...

  2. mysql 插入Emoji表情报错

    今天做的了个获取微信粉丝的功能,发现将昵称插入数据库报错.长度肯定是够的 Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F 找了点资料发现UTF-8编 ...

  3. Spring3.2 HelloWorld

    直接上图吧: jar包: 项目文件夹一览: 这里的HelloWeb-servlet,xml 是在WEB-INF 下 HelloController: package com.cqu.tutorial; ...

  4. Directx11学习笔记【十一】 画一个简单的三角形--effect框架的使用

    这里不再介绍effect框架的具体使用,有关effect框架使用可参考http://www.cnblogs.com/zhangbaochong/p/5475961.html 实现的功能依然是画一个简单 ...

  5. fiddler打开后 浏览器就上不了网的解决方法

    fiddler设置一下即可 Tools fiddler options connections 不要选中 Act as system proxy on startup

  6. win7开机直接进入系统系统桌面

    在开始搜索栏输入:netplwiz   选中admin用户(也就是你登录的用户名),然后在把上面的勾去掉,点应用,会提示输入用户名和密码,输二次,是一样的密码,如果没设密码,就不用输直接应用,确定就O ...

  7. docker-gitlab(转)

    Issues Docker is a relatively new project and is active being developed and tested by a thriving com ...

  8. 【夯实基础】javakeywordsynchronized 详细说明

    尊重版权:http://www.cnblogs.com/GnagWang/archive/2011/02/27/1966606.html Java语言的keyword.当它用来修饰一个方法或者一个代码 ...

  9. 大约session_cached_cursors在不同的db在默认不同的版本号

    大约session_cached_cursors的值,不同db版本号具有不同的默认值: 9i是 0 10.1 0 10.2 是20 11.1 是50 11.2 是50 12.1 是50 值值得注意的是 ...

  10. Source insight 3572安装和版本号An invalid source insight serial number was detected解

    Source insight最新版本3572 下载链接:http://www.sourceinsight.com/down35.html,   http://www.sourceinsight.com ...