2014-11-19 3 views
0

CollectionView의 셀을 선택하면 새보기가로드됩니다.CollectionViewCell에서 신속하게 새보기를 표시하지 못했습니다.

모든 지역 온라인은 새로운보기 및 스토리 보드의 네비게이션 컨트롤러를 등록하는 것만 큼 간단 말한다 다음 Ctrl 키 + 새보기 내 CollectionViewCell에서 드래그를 클릭합니다.

코드를 컴파일하고 실행하지만 셀을 클릭해도 새로운 뷰가 표시되지 않습니다. 나는 무엇을 놓쳤는가? 여기 내 CollectionView 컨트롤러 코드 :

스토리 보드는

편집 ...이 (정확한 이름과 모든 식별) 나의 다음 뷰 CollectionView에서 SEGUE이다, 그래서 조금 혼란 스러워요 말한다 내가 여기에서 뭔가를했을 경우를 대비해서 문제를 일으키고 있습니다. 비슷한 문제를 가진 사람들을위한

IBOutlet weak var calendarCollection: UICollectionView! 
var collectionView: UICollectionView? 
let calendarCellIdentifier: String = "calendarCell" 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() 
    layout.sectionInset = UIEdgeInsets(top: 50, left: 10, bottom: 10, right: 10) 
    layout.itemSize = CGSize(width: 60, height: 60) 
    collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout) 
    collectionView!.dataSource = self 
    collectionView!.delegate = self 
    collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: calendarCellIdentifier) 
    collectionView!.backgroundColor = UIColor.blackColor() 
    self.view.addSubview(collectionView!) 
} 

// Return the collectionView cell at IndexPath 
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(calendarCellIdentifier, forIndexPath: indexPath) as UICollectionViewCell 
    cell.backgroundColor = UIColor.blueColor() 
    return cell 
} 

func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return true 
} 

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return challengeDurationDays 
} 
+0

셀에서보기가 아닌 셀에서 실제로 세그먼트를 만들 었는지 확인하십시오. 당신은 segue의 원을 클릭하여 확인할 수 있습니다. 셀이 강조 표시되면 segue가 올바른 것입니다. 전체보기가 강조 표시되면 segue가 올바르지 않습니다. – dasdom

+0

셀이 하이라이트되므로, 그렇지 않습니다. 내 코드가 만들어지고 실행됩니다. 셀을 클릭 할 때 아무 것도하지 않습니다. – SwoopsFromAbove

+0

당신의 segue가 push segue라고 가정합니다. 그렇다면 뷰 컨트롤러가 내비게이션 컨트롤러에 내장되어 있습니까? – dasdom

답변

0

, 나는 수동으로 didSelectItemAtIndexPath 방법을 사용하여 SEGUE을 유발하여이를 해결 : (당신은 아마 코드에서 말할 수있는)이 캘린더 페이지입니다. 나는이 일을해야한다고 생각하지 않지만, 오해했을 것입니다. 그것 또는 버그입니다. 나는 결국 CollectionViewController에 추가하는 방법은 다음과 같습니다

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 
    performSegueWithIdentifier("dayViewSegue", sender: calendarCollection) 
} 
0

내가 (아이폰 OS 8 앱 엑스 코드 6.1.1을 사용하여) CollectionView와 비슷한 문제가 있었다. 내 스토리 보드에서 섹터를 CollectionViewCell에서 다른 ViewController으로 설정했지만 셀을 터치하면 자동으로 작동하지 않습니다. 또한 CollectionViewCell을 서브 클래 싱하고 내 스토리 보드에있는 셀의 클래스를 맞춤 클래스 (MazeCollectionViewCell)로 설정하고 내 클래스에서 이미지 보드에 연결된 IBOutlets을 설정하고 스토리 보드 셀에 배치 한 라벨을 연결했습니다. 그러나 collectionView cellForItemAtIndexPath 메서드에서 이미지 및/또는 레이블에 액세스하려고 시도했지만 이미지가 없습니다. I 내에서의 viewDidLoad 방법registerClass 호를 제거 할 때

내 모든 문제가 해결되었다 [제 경우, I는 collectionView!.registerClass(MazeCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 제거]. 그게 다야!

추측registerClass 호출이 내가 지정한 클래스의 빈 복사본을 생성하고 세포가 생성되는에 따라서 내 SEGUE 내 콘센트에 연결이 유효하지 않았다 (스토리 보드에서 템플릿을 무시하도록 CollectionViewController의 원인이다 컬렉션의 경우).

누군가가 더 깊은 통찰력을 가지고 있다면, 나는 그것을 듣고 싶습니다. 그러나 그것은 저에게 효과가있는 해결책입니다.

관련 문제