2017-01-07 36 views
0

嘿傢伙我有一種情況我不能籠罩我的頭。我將如何計算Segued View Controller的indexPath?當我從我的CollectionViewCell繼續時,我從單元格獲得索引數據。到現在爲止還挺好。計算indexPath然後重新加載數據?斯威夫特3

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 

    let sales: Sales! 
    let tSale: [Sale] = revenueData.tSale 
     sales = tSales[indexPath.row] 
    DispatchQueue.main.async { 
     self.performSegue(withIdentifier: "detailedView", sender: sales) 
    } 
} 

`

現在,我需要重新加載數據到從下一indexPath從第二視圖控制器內呈現信息。我想我可能需要獲取它必須重新加載到另一個索引中的indexPath數據。我怎樣才能做到這一點?

回答

0

UIViewController中有一個掛鉤用於在顯示之前配置新的視圖控制器。像這樣的東西可能會起作用。

self.performSegue(withIdentifier: "detailedView", sender: (sales, indexPath.row)) 

然後

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    guard 
     let sender = sender, 
     let (sale, row) = sender as? (Sale, Int) 
     else { return } 

    segue.destination.sale = sale 
    segue.destination.saleIndex = row 
}