NSIndexPath:从 CoreData 中检索数据
NSIndexPath: retrieving data from CoreData
我在我的词典应用程序中使用 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?
感谢阅读。
也许会
destination.receivedindexPath = NSIndexPath(forRow: indexPath.row, inSection: 0)
或
destination.receivedindexPath = NSIndexPath(forRow: indexPath.row, inSection: 1)
假设目标表视图有一个部分
我在我的词典应用程序中使用 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?
感谢阅读。
也许会
destination.receivedindexPath = NSIndexPath(forRow: indexPath.row, inSection: 0)
或
destination.receivedindexPath = NSIndexPath(forRow: indexPath.row, inSection: 1)
假设目标表视图有一个部分