【发布时间】:2015-11-23 10:46:15
【问题描述】:
我是 swift 新手,我被这个错误困住了。我有一个 viewController,它有一个集合视图,它有一个 viewContoller 的故事板 segue 和两个按钮,它们有一个 push segue 到其他一些 viewController。当我尝试点击这些按钮时,会出现一个致命错误,即 sender 不是具有以下代码的 collectionView。
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
if let cell = collectionViewOne.cellForItemAtIndexPath(indexPath)
{
performSegueWithIdentifier("showDeals", sender: cell)
}
else
{
// Error indexPath is not on screen: this should never happen.
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
assert(sender as? UICollectionViewCell != nil, "sender is not a collection view")
if let indexPath = self.collectionViewOne?.indexPathForCell(sender as! UICollectionViewCell) {
if segue.identifier == "showDeals" {
let detailVC: DealsTableViewController = segue.destinationViewController as! DealsTableViewController
detailVC.someCategory = MyIds[indexPath.row]
}
} else {
// Error sender is not a cell or cell is not in collectionView.
}
}
【问题讨论】:
-
不确定这是不是答案,但您应该先检查标识符是否为 showDeals,然后再进行其余的操作。
-
我已经检查了标识符,它似乎是 showDeals。
标签: ios swift uicollectionview segue