0

我已经做了集合视图有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) 
    } 

} 

回答

0

你missusing塞格斯。 Segues创建其目标ViewController的新实例,这意味着当你启动你的应用程序时你有1个CollectionViewController,然后你点击一个单元,你有一个1 CollectionViewController和1 FirstViewController的堆栈,然后你点击按钮,喜欢它,你是不是又回到原来的collectionViewController,而是要创建一个新的,这意味着你现在有1 collectionViewController,一个第一的viewController和一个collectionViewController。

这就是为什么你reexcecuting viewDidLoad中,这就是为什么它会失败,因为平移手势识别已经添加到另一个视图....

如果你想实现平(推流行/大师 - >细节/后退按钮......),你应该封装你collectionViewController在NavigationViewController和使用自由还给按钮:不处理BACK自己,尤其是SEGUE

PS的确切beeing的缘故,而是对于一个广告公众来说:存在一种特殊的继续处理方式,他们被称为放松继续。但是,UINavigationController应始终是平面导航的首选选项。放松与垂直导航打交道时赛格瑞发现其使用(模式演示/ OK - 取消)

+0

谢谢你的解释,但问题是,当我添加一个导航控制器并将其连接到集合视图(与Relationship'根视图控制器“)时,我不会得到按钮或导航栏,当我在FirstCollectionViewController(在模拟器中),但当我在main.storyboard里面时,我看到了导航栏,但没有看到按钮。 –

1

你并不需要获得在细胞外

制作设定值

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{ 
    //set value here 
    if self.currentTitle == "1"){ 
    // 
    } 
    else { 
    //... 
    } 

} 

,并重新加载特定的细胞

let indexPath = IndexPath(item: i, section: 0) 
self.tableView.reloadRows(at: [indexPath], with: .automatic) 

希望它会使帮助你:)

相关问题