0
我在我的字典應用中使用CoreData
,我想要實現的是顯示tableview
列中的單詞列表,並且我已成功實現該功能。另外,我設法通過segue將indexPath
的值傳遞給另一個swift文件。NSIndexPath:從CoreData中檢索數據
由於這兩個文件都從同一個數據庫獲取數據,所以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。 – vadian