2017-03-28 5 views
0

안녕하세요 저는 초보자이며 아주 기본적인 segue에 갇혀 있습니다! 난 그냥 당신이 당신이 단순히 subscript으로 배열에 접근 할 필요가 SEGUE로 값을 전달하려면 보낸 사람, 예를 들면 샌들 [indexPath.row] sandalName에 대한 감사Swift 3 UICollectionView 셀의 Segue

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! shoeCollectionViewCell 
    let sandalCell = sandals[indexPath.row] 
    cell.sandalImage.image = UIImage(named: sandalCell["image"]!) 
    cell.sandalStyleName.text = sandalCell["styleName"] 
    cell.sandalPrice.text = sandalCell["price"] 
    return cell 
} 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "shoeDetailSegue"{ 
     var detailPage = segue.destination as! shoeDetailViewController 
     let selectedCell = sender as! UICollectionViewCell 
     let indexPath = collectionView?.indexPath(for: cell) 
     detailPage.getName = sandals[indexPath!.row].sandalName 
     detailPage.getPrice = sandals[indexPath!.row].sandalPrice 
     detailPage.getImage = sandals[indexPath!.row].sandalImage 
    } 
} 
+0

http://stackoverflow.com/a/41887007/5461400이 –

+0

은 참고로 우리에게 sandals' 배열 –

+0

'의 선언을 표시하려고 : 같은'var에 detailPage = segue.destination! shoeDetailViewController'는 'var detailPage = segue.destination as'이어야합니다! ShoeDetailViewController'는 잘못된 변수 이름 규칙을 무시합니다. – TheCodingArt

답변

2

를 사용하여 올바른 구문을 찾으려면 당신이하는 방식은 cellForItemAt입니다.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "shoeDetailSegue"{ 

     var detailPage = segue.destination as! shoeDetailViewController 
     let selectedCell = sender as! UICollectionViewCell 
     let indexPath = collectionView?.indexPath(for: cell) 
     let sandal = sandals[indexPath!.row] 
     detailPage.getName = sandal["styleName"]! 
     detailPage.getPrice = sandal["price"]! 
     detailPage.getImage = UIImage(named: sandal["image"]!) 
    } 
} 
관련 문제