gpt4 book ai didi

ios - UICollectionView prepareForSegue indexPathForCell 为零 iOS 9

转载 作者:行者123 更新时间:2023-11-28 12:45:24 27 4
gpt4 key购买 nike

问题是这一行返回零:

if let indexPath = self.collectionView?.indexPathForCell(sender as! UICollectionViewCell) 

因此我无法传递任何信息,标识符已设置且委托(delegate)已设置。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "DetalleSegueIdentifier" {
if let indexPath = self.collectionView?.indexPathForCell(sender as! UICollectionViewCell) {
let detailVC = segue.destinationViewController as! DetalleNoticiaViewController
detailVC.contact = self.noticia[indexPath.row]
}
}
}

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("DetalleSegueIdentifier", sender: collectionView.cellForItemAtIndexPath(indexPath))
}

有什么帮助吗?

最佳答案

问题是如何尝试取回单元格。您必须在 performSegueWithIdentifier 中传递单元格,然后在 prepareForSegue 中恢复它。这是代码:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("DetalleSegueIdentifier", sender: collectionView.cellForItemAtIndexPath(indexPath))
}

然后

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "DetalleSegueIdentifier" {
if let cell = sender as? UICollectionViewCell{
let indexPath = self.collectionView!.indexPathForCell(cell)
let detailVC = segue.destinationViewController as! DetalleNoticiaViewController
detailVC.contact = self.noticia[indexPath.row]

}

}
}

希望对您有所帮助!

关于ios - UICollectionView prepareForSegue indexPathForCell 为零 iOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38257535/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com