2016-04-05 74 views
0

我在我的字典應用中使用CoreData,我想要實現的是顯示tableview列中的單詞列表,並且我已成功實現該功能。另外,我設法通過segue將indexPath的值傳遞給另一個swift文件。NSIndexPath:從CoreData中檢索數據

由於這兩個文件都從同一個數據庫獲取數據,所以indexPath已經足夠好了,我可以在另一個視圖控制器中顯示它。

但是,我想要實現左右滑動功能以在視圖控制器中顯示其他詞語。當沒有部分時很容易。

這是我在UITableViewController.swiftsegue

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?

感謝您的閱讀。

+0

可以增加和通過獲取行部分遞減指數路徑,修改和創建如果行值小於fetchedResultsController中的項目數,則新建indexPath。 – vadian

回答

1

也許做

destination.receivedindexPath = NSIndexPath(forRow: indexPath.row, inSection: 0) 

destination.receivedindexPath = NSIndexPath(forRow: indexPath.row, inSection: 1) 

假定目標的tableview有一個部分