2016-09-23 3 views
0

ViewController에서 UICollection보기가 있는데 didSelectItemAtIndexPath에 전혀 응답하지 않습니다.Swift UICollectionView : didSelectItemAtIndexPath 응답이 없습니다.

// super class 
class ViewController: UIViewController, iCarouselDelegate, iCarouselDataSource, UICollectionViewDelegate, UICollectionViewDataSource { 

    @IBOutlet weak var collectionView: UICollectionView! 


// delegate 
override func viewDidLoad() { 
     super.viewDidLoad() 

     // collection view delegate and datasource 
     collectionView.delegate = self 
     collectionView.dataSource = self 


// did select item 
     func collectionView(collectionView: UICollectionView!, didSelectItemAtIndexPath indexPath: NSIndexPath!) { 

      print(indexPath) 

     } 

그리고이 대표단은 IB. UiCollectionView delegate in IB

+0

이봐, 난 알고있다 세포에있는 버튼이 있습니다. 또는 customCell의 내용은 무엇입니까? –

+0

내가 질문을 올렸을 때 버튼이없고 이미지와 레이블 만있었습니다. 이제이 문제를 어떻게 해결했는지이 질문에 대답했습니다. go 내 대답을 확인하십시오. –

답변

0

여러 가지 추측이 도움이 될 수 있습니다

  • 가 실수로 - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath을 무시 했습니까? 일부 높은 우선 순위 UIGestureRecognizer 같은 UIResponderUIButton 셀 또는 서브 뷰에 추가 한 경우

  • 확실히 대신

+0

아니요. 감사합니다. @Chen Wei –

+0

저는 같은 viewController에서 ICarousel을 가지고 있는데, 이유를 말씀해주십시오. @Chen Wei –

+0

아니요, '@IBOutlet collectionview'를 스토리 보드의 컬렉션보기에 연결 했습니까? 그렇다면 스크린 샷의 이름은 기본 이름 인 "Collection View"대신 "collectionview"변수와 동일해야합니다. –

0

내가 다른를 사용했다 방법은 호출해야 해당 사실

  • collectionView.userInteractionEnabled을 설정 만든다 방법은이 문제에서 벗어나 내 프로젝트를 제 시간에 제공하는 것입니다.

    난 "cellForItemAtIndexPath"내 셀 내부 및이 방법에있어서의 버튼을 만들어과 같이 그것을 대상 덧붙여

    imageButton.addTarget(self, action: #selector(ViewController.imageButtonAction(_:)), forControlEvents: UIControlEvents.TouchUpInside) 
    

    때문에 같은 버튼 태그 선택된 indexPath.row 합격 :

    imageButton.tag = indexPath.row 
    
    이 내 작업 :

    func imageButtonAction(sender: UIButton) { 
    
    let categoryId = categories[sender.tag]["id"] 
        let categoryName = categories[sender.tag]["category_name"] 
    
        let mainCategory = self.storyboard?.instantiateViewControllerWithIdentifier("MainCategoryViewController") as! MainCategoryViewController 
        mainCategory.mainCategoryId = categoryId! 
        mainCategory.title = categoryName! 
        self.navigationController!.pushViewController(mainCategory, animated: true) 
    
    } 
    
  • 관련 문제