我已经做了集合视图有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里面时,我看到了导航栏,但没有看到按钮。 –