一个数据表对象(NSManagedObject)加入排序
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)加入排序的更多相关文章
- ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法
ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块 --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...
- Oracle 11g系列:数据表对象
Oracle数据库的下一层逻辑结构并非数据表,而是表空间.每个数据表都属于唯一的表空间. 1.Oracle表空间 与数据表相同,Oracle表空间是一个逻辑对象,而非物理对象,是数据库的组成部分.当使 ...
- 【SQL Sever】将SQL Sever中的一个数据表的数据导出为insert语句
例如:这SQL Sever中的一张数据表,想要将这张数据表中的数据 转化成一个一个的insert语句存储在txt的文档中,那么不论走到那里这个insert语句一执行,我们就能将这个数据表中的数据 ...
- oracle表空间查询维护命令大全之中的一个(数据表空间)史上最全
表空间是数据库的逻辑划分,一个表空间仅仅能属于一个数据库. 全部的数据库对象都存放在建立指定的表空间中.但主要存放的是表, 所以称作表空间.在oracle 数据库中至少存在一个表空间.即S ...
- 使用Mybatis Generator 生产 AS400中的数据表对象
第一次使用Mybatis,由于公司核心服务器是AS400,参考了网络各个大大的教程后,发现无法使用Mybatis Generator自动生成AS400中的表对象 参考URL: http://www.c ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:数据表对象
create table students( stuno ) not null, --学号 stuname ), --姓名 sex ), --性别 age int, --年龄 departno ) n ...
- PHP array_multisort() 函数详解 及 二维数组排序(模拟数据表记录按字段排序)
一.先看最简单的情况. 有两个数组: $arr1 = array(1, 9, 5); $arr2 = array(6, 2, 4); array_multisort($arr1, $arr2); pr ...
- oracle恢复一个数据表的方法
今天提交给客户方一个sql脚本去跟新历史数据,结果客户那边的部署人员犯了一个错误,直接拿系统账号去部署,结果第一段代码没有执行成功,结果第二段代码却执行成功了,并且已经提交了的,....由于事前没有备 ...
- 一个数据表通过另一个表更新数据(在UPDAT语句中使用FROM子句)
在sql server中,update可以根据一个表的信息去更新另一个表的信息. 首先看一下语法: update A SET 字段1=B表字段表达式, 字段2=B表字段表达式 from B WHE ...
随机推荐
- iSwifting如何发送照片社区
登录iSwifting社区 1,首先点击"帖子": 2,点击"照片": 3.点击"选择文件上传" 4,上传后的照片: 5,点击上传的照片: ...
- android下调试声卡驱动之概述
在Android中音频系统使用的是ALSA系统架构.ASoC--ALSA System on Chip .是建立在标准ALSA驱动层上,为了更好地支持 嵌入式处理器和移动设备中的音频Codec的一套软 ...
- MVC过滤器的详细讲解和示范样本
MVC共有4个过滤器:ActionFilter(方法过滤器),ResultFilter(结果过滤器.感觉是不是很好,所以称它为),AuthorizationFilter(授权过滤器).Exceptio ...
- jQuery 焦点图,图像文件js档
jQuery 焦点图,图片文件在js文件里 演示 XML/HTML Code <div id="photo_container"></div> JavaSc ...
- 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern)
原文:乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) 作者:webabc ...
- 引用第三方框架 不支持ARC
我们会常常遇到一个问题就是引用第三方框架之后发现不支持内存的自己主动处理(ARC) 我们须要这样来操作: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdT ...
- Ural 1309 Dispute (递归)
意甲冠军: 给你一个数列: f(0) = 0 f(n) = g(n,f(n-1)) g(x,y) = ((y-1)*x^5+x^3-xy+3x+7y)%9973 让你求f(n) n <= 1e ...
- hibernate它 10.many2many单向
在前文hibernate之5.many2one单向提到多对多关系,表结构设计是基于中间表来实现, 以下以用户与角色(多对多)为例,在Hibernate是怎样操作的 表结构设计: 类图: CRUD; S ...
- android 常见的解决(mdpi、hdpi 、xhdpi、xxhdpi )屏幕调整
查询到执行的system service后,就能够在dumpsys后面加上service的名字,查看指定的service信息. adb shell dumpsys activity adb shell ...
- 【DataStructure】Some useful methods about linkedList(三)
Method 4: Gets the value of element number i For example, if list is {22, 33, 44, 55, 66, 77, 88, 99 ...