0

4 개의 셀이 포함 된 컬렉션보기를 만들었고 셀 1의 버튼을 누르면 (다른 셀을 아직 만들지 않은 것입니다) "FirstCollectionViewController"라는 새로운 ViewController로 이동합니다. 컬렉션보기에서 스 와이프 할 때 슬라이드 아웃 메뉴를 보여주는 pangesturderecognizer가 있습니다.PanGesture로 인해 신속하게 EXC_BAD_INSTRUCTION (코드 = EXC_1386_INVOP, subcode = 0x0)을 얻는 중

그러나 "FirstCollectionViewController"에있는 상태에서 컬렉션보기로 돌아가려면 왼쪽 모서리에있는 단추를 누를 수 있습니다. 그러나 그것을 누를 때 CollectionViewController의 ViewDidLoad 내부에있는 "self.view.addGestureRecognizer (self.revealViewController(). panGestureRecognizer())"에서 EXC_BAD_INSTRUCTION 오류가 발생합니다. panGestureRecognizer를 ViewDidAppear에 넣으려고했으나 같은 일이 발생했습니다

어떻게 고칠 수 있습니까?

은 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. Segues는 대상 ViewController의 새 인스턴스를 만듭니다. 즉, 응용 프로그램을 시작할 때 CollectionViewController가 1 개 있고 셀을 클릭하면 CollectionViewController와 FirstViewController가 하나씩 스택 된 다음 단추를 누르고 이벤트를 봅니다. 그것과 같이 원래 CollectionViewController로 돌아 오지는 않지만 새로운 콜렉션 뷰를 생성하고 있습니다. 즉, 콜렉션 뷰 컨트롤러 1 개, 첫 번째 뷰 컨트롤러 1 개, CollectionViewController 콜렉션 1 개를 갖게됩니다. 당신의 viewDidLoad을 reexcecuting 이유

이것은

당신이 플랫 (푸시 팝을 구현하려면

/마스터 ....는 팬 제스처 인식기가 이미 다른 뷰에 추가 되었기 때문에 실패 할 이유가있다 -> 세부/뒤로 버튼 ...) 당신이 NavigationViewController에 collectionViewController을 캡슐화하고 자유롭게 다시 주어진 버튼을 사용한다 : 특히 SEGUE으로, BACK 자신을 처리하지 않는 을 정확한 beeing는의 이익을 위해

PS하지만, 광고 된 대중을 위해 : 특별한 종류의 segue가 뒤를 다루기 위해 존재하며, 그들은 unwind segue라고 불립니다. 그러나 UINavigationController는 항상 평면 탐색에 대한 기본 옵션이어야합니다.

+0

설명해 주셔서 감사합니다.하지만, 네비게이션 컨트롤러를 추가하고 콜렉션 뷰 (관계 '루트보기 컨트롤러'와 함께)에 연결하면 버튼이나 탐색 바가 나타나지 않습니다. FirstCollectionViewController (시뮬레이터에서)하지만 main.storyboard 안에있을 때 탐색 모음을 볼 수 있지만 버튼은 볼 수 없습니다. –

1

당신은

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

} 

만들기 설정 값 이외의 셀을받을 필요가 없습니다 - (취소 모달 프리젠 테이션/OK)하고 다시로드 SEGUE 수직 탐색을 다룰 때 사용을 찾아 휴식을 취 특정 셀

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

는 당신을 위해 도움을 만들 것입니다 희망 :

관련 문제