当我在运行时点击单元格时,程序似乎打破了,我得到了这个:
EXC_BREAKPOINT(code=EXC_I386_BPT,subcode=0x0
直到我从collectionviewcell
创建一个segue到新的视图控制器时,我才遇到这个问题。
这是我的主视图控制器和视图控制器的代码:
主视图控制器:
class FlashViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var collectionView: UICollectionView!
var decks: [Deck] = []
override func viewDidLoad() {
super.viewDidLoad()
// Move on ...
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 75, left: 20, bottom: 10, right: 20)
layout.itemSize = CGSize(width: 150, height: 200)
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
self.collectionView.dataSource = self
self.collectionView.delegate = self
collectionView.registerClass(DeckCollectionViewCell.self, forCellWithReuseIdentifier: "DeckCollectionViewCell")
collectionView.backgroundColor = UIColor.whiteColor()
self.view.addSubview(collectionView!)
var deck1 = Deck()
deck1.name = "SAT is the bomb"
self.decks.append(deck1)
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.decks.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var deck = self.decks[indexPath.row]
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("DeckCollectionViewCell", forIndexPath: indexPath) as DeckCollectionViewCell
cell.backgroundColor = UIColor.blackColor()
cell.textLabel?.text = deck.name
cell.textLabel.textColor = UIColor.whiteColor()
cell.imageView?.image = UIImage(named: "circle")
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("decksToCardsSegue", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var nextViewController = segue.destinationViewController as NewDeckViewController
nextViewController.deckCollection = self
}
}
新视图控制器:
class DeckViewController : UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
// Move on ...
}
}
答案 0 :(得分:0)
检查您的Storyboard Segue标识符是否为“decksToCardsSegue”,检查您的标识符下的Segue and Segue Class并确保它们是正确的。