【发布时间】:2016-04-05 06:14:27
【问题描述】:
我在我的字典应用程序中使用CoreData,我想要实现的是在tableview 的列中显示单词列表,我已经成功实现了这一点。另外,我已经设法通过 segue 将 indexPath 值传递给另一个 swift 文件。
由于两个文件都从同一个数据库中获取数据,indexPath 已经足够好,我可以在另一个视图控制器中显示它。
但是,我想实现左右滑动功能以在视图控制器中显示其他单词。当没有部分时,这很容易。
这是我在UITableViewController.swift 中为segue 提供的内容:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showWordDetail" {
let destination = segue.destinationViewController as! WordDetailViewController
if let indexPath = self.tableView?.indexPathForCell(sender as! EduDicTableViewCell) {
destination.receivedindexPath = indexPath
}
}
}
这是来自UIViewController.swift 接收indexPath 的代码:
let object = fetchedResultsController?.objectAtIndexPath(receivedindexPath) as? WordItem
wordLabel.text = object?.word
这是IndexPath的输出:
<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}
无论如何我可以显示其他数据,使用修改后的indexPath?
感谢阅读。
【问题讨论】:
-
如果行值小于 fetchedResultsController 中的项目数,您可以通过获取行部分来增加和减少索引路径,修改它并创建一个新的 indexPath。
标签: ios swift core-data nsindexpath