我已經做了集合視圖有4個細胞,當你按在小區1按鈕(我還沒有做出其他的細胞還)將採取你到一個叫做「FirstCollectionViewController」的新的ViewController。我有一個pangesturderecognizer顯示滑出菜單時,你在集合視圖刷卡。獲取EXC_BAD_INSTRUCTION(代碼= EXC_1386_INVOP,子碼=爲0x0),因爲PanGesture的迅速
但是,當你在「FirstCollectionViewController」,你想回來到集合視圖,您可以按下左側角落的按鈕了。但是,當我按下它,我將在得到一個EXC_BAD_INSTRUCTION錯誤「self.view.addGestureRecognizer(self.revealViewController()。panGestureRecognizer())」的viewDidLoad中的CollectionViewController內。我試圖把在ViewDidAppear的panGestureRecognizer但同樣的情況
我怎樣才能解決這個問題?
BTW應該送你回集合視圖的SEGUE被稱爲: 「SegueFirstCollectionViewController」
CollectionViewController:
import Foundation
import UIKit
class CollectionViewController: UICollectionViewController {
var Array = [String]()
var ButtonArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
Array = ["1","2","3","4"]
ButtonArray = ["1", "2", "3", "4"]
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
override func viewDidAppear(animated: Bool) {
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return Array.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell
let Label = cell.viewWithTag(1) as! UILabel
Label.text = Array[indexPath.row]
let Button = cell.viewWithTag(2) as! UIButton
Button.setTitle(ButtonArray[indexPath.row], forState: UIControlState.Normal)
// Button.addTarget(self,action:#selector(ButtonArray(_:)), forControlEvents:.TouchUpInside)
Button.addTarget(self, action: Selector("ButtonArray:"), forControlEvents:.TouchUpInside)
return cell
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Inside didSelectItemAtIndexPath")
}
func ButtonArray(sender : UIButton) {
print("m")
if sender.currentTitle == "1"{
performSegueWithIdentifier("segueFirst", sender: nil)
}
if sender.currentTitle == "2"{
}
if sender.currentTitle == "3"{
}
if sender.currentTitle == "4"{
}
}
}
FirstCollectionViewController:
class FirstCollectionViewController : UIViewController {
@IBAction func SegueFirstCollectionViewController(sender: UIButton) {
performSegueWithIdentifier("SegueFirstCollectionViewController", sender: nil)
}
}
謝謝你的解釋,但問題是,當我添加一個導航控制器並將其連接到集合視圖(與Relationship'根視圖控制器「)時,我不會得到按鈕或導航欄,當我在FirstCollectionViewController(在模擬器中),但當我在main.storyboard裏面時,我看到了導航欄,但沒有看到按鈕。 –