小编Mas*_*lko的帖子

如何使用UIcollectionView进行prepareForSegue

我有这个代码的问题:

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

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetailsSegue" {
        let detailsVC: DetailsViewController = segue.destinationViewController as! DetailsViewController
        let indexPaths = self.collectionView.indexPathsForSelectedItems()
        let indexPath = indexPaths[0] as! NSIndexPath
         var thisCoupon = self.userCoupons[indexPath.row] as UserCoupons
         detailsVC.userCoupon = self.userCoupons[indexPath.row]
        detailsVC.pinArray = self.pinArray
        detailsVC.userStamp = self.userStamps[indexPath.row]

    }

}
Run Code Online (Sandbox Code Playgroud)

当我在集合视图中只有一个项目时,我无法访问DetailsViewController.当我的物品很少时,我的segue可以处理没有最后一项的物品.

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return self.userCoupons.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { …
Run Code Online (Sandbox Code Playgroud)

uicollectionview swift

4
推荐指数
1
解决办法
4373
查看次数

标签 统计

swift ×1

uicollectionview ×1