【发布时间】:2015-07-05 21:47:07
【问题描述】:
我有一个自定义 UITableView 类来处理表格视图的动画,并且已经使用在表格视图中显示的Array 测试了以下代码。
tableView.didMoveCellFromIndexPathToIndexPathBlock = {(fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) -> Void in
self.objectsArray.exchangeObjectAtIndex(toIndexPath.row, withObjectAtIndex: fromIndexPath.row)
}
这适用于基本数组,但我实际上想重新排列 NSSet 类型的托管对象。因此,在我的文件中,我声明了以下内容,它创建了返回表视图使用的 Item 类型的数组。
文件夹类函数:
func itemArray() -> [Item] {
let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
return iist.sortedArrayUsingDescriptors([sortDescriptor]) as! [Item]
}
表格视图控制器声明
var itemArray = [Item]()
itemArray = folder.itemArray() //class function to return a NSArray of the NSSET [Item]
我正在尝试这样做,因此在重新排列单元格时它会更改 NSSet 的顺序,以便在应用程序重新加载时保存它,有人有什么建议吗?
【问题讨论】:
标签: ios arrays swift uitableview core-data