미친 날이 며칠 지나면 내 문제의 해결책을 찾을 수 없었습니다. 문제는 다음과 같습니다. UICollectionView
에서 셀을 선택한 후 didSelectItemAtIndexPath
메서드가 호출되지 않습니다.didSelectItemAtIndexPath of UiCollectionView가 호출되지 않았습니다.
내보기 구조는 다음이보기는 제어기에 의해 관리된다
다음있다 방법 :override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidLoad() {
super.viewDidLoad()
initCategoriesCollection()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func initCategoriesCollection(){
let ccVC : CategoriesCollectionViewController = UIStoryboard(name:"CandidateProfile",bundle:nil).instantiateViewControllerWithIdentifier("categoriesController") as! CategoriesCollectionViewController;
addChildViewController(ccVC)
ccVC.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
containerView.addSubview(ccVC.view)
ccVC.didMoveToParentViewController(self)
}
용기 뷰 상기 구조는 다음 :
그리고이 컨테이너보기 이러한 방법을 구현 이는의 ViewController에 의해 관리됩니다 :
// tell the collection view how many cells to make
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.e1Categories.count
}
// make a cell for each cell index path
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CategoryCollectionViewCell
// Use the outlet in our custom class to get a reference to the UILabel in the cell
cell.categoryName.text = self.e1Categories[indexPath.item].string
cell.categoryName.numberOfLines = 0
cell.categoryName.sizeToFit()
cell.categoryName.textAlignment = .Center
cell.categoryCircle.makeCircle()
return cell
}
// MARK: - UICollectionViewDelegate protocol
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// handle tap events
print("You selected cell #\(indexPath.item)!")
}
사람이 무슨 일이 일어나고 있는지 알고 있나요? 터치 이벤트를 가로 챌 수도 있기 때문에 ScrollView를 제거하려고했지만 아직 작동하지 않습니다. 여기 Stackoverflow에서 다른 질문을 읽은 후 그 중 아무 것도 나를위한 해결책이 없습니다.
미리 감사드립니다.
편집 :
내가 연결 한 내 delegate
당신이 아래의 그림에서 볼 수있는 스토리 보드를 통해 dataSource
: 당신의 initCategoriesCollection()
에서
에 '대리인'이 연결되어 있습니까? – holex
'ccVC.delegate = self'를 추가하면'initCategoriesCollection' 메쏘드에서 트릭을해야합니다 – EBDOKUM
@holex 예, 스토리 보드를 통해 연결했습니다. 나는 그것의 포획을 가진 포스트를 편집했다. @EBDOKUM 다음 문제를 제기하면 '값 유형'CategoriesCollectionViewController '에'delegate '멤버가 없습니다. – kikettas