UICollectionView에서 탭한 셀의 indexPath를 다른 뷰 컨트롤러로 전달하려고합니다.CollectionViewCell에서 다른 뷰 컨트롤러로 Seague 전달 IndexPath
보기 컨트롤러 "PostCell에 형 포스트의 캐스팅 할 수 없습니다 값": 내가 선택한 일의 indexPath를 얻을
나는이 오류가 다음 뷰 컨트롤러에 SEGUE 수없는 것 # 1 :
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let post = posts[indexPath.row]
if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("PostCell", forIndexPath: indexPath) as? PostCell {
cell.configureCell(post)
}
return cell
}
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let selectedPost: Post!
selectedPost = posts[indexPath.row]
performSegueWithIdentifier("PostDetailVC", sender: selectedPost)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "PostDetailVC" {
//Error here: Could not cast value of Post to PostCell
if let selectedIndex = self.collection.indexPathForCell(sender as! PostCell){
print(selectedIndex)
}
if let detailsVC = segue.destinationViewController as? PostDetailVC {
if let selectedPost = sender as? Post {
print(selectedIndex)
detailsVC.post = selectedPost
detailsVC.myId = self.myId!
detailsVC.indexNum = selectedIndex
}
}
}
}
보기 컨트롤러 # 2 :
var indexNum: NSIndexPath!
override func viewDidLoad() {
super.viewDidLoad()
print(indexNum)
}
아주 좋은에게 전달하는 것이 좋습니다! 나는 확실히 이해한다. 고마워요! – kelsheikh