2016-12-12 10 views
-1

UICollectionViewCell에 문자열을 표시해야합니다. 사용자 정의보기 셀을 만들었습니다. 나는 응용 프로그램을 실행할 때마다 그러나 "심각한 오류 : 옵션 값 풀기 동안 예기치 않게 전무 발견"이 표시 채팅에서 우리의 논의에서CollectionView 셀에서 문자열을 표시하는 방법은 무엇입니까?

func numberOfSections(in collectionView: UICollectionView) -> Int { 
    return 1 
} 

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return places.count 
} 

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PlaceCollectionViewCell 

    cell.layer.borderWidth = 0.5 
    cell.layer.borderColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00).cgColor 

    //cell.placeLabel.tintColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00).cgColor 

    cell.layer.cornerRadius = 35 
    cell.layer.masksToBounds = true 

    //cell.placeLabel.text = places[indexPath.row] as! String 
    cell.placeLabel.text = places[indexPath.row] 

    return cell 
} 
+0

오류 메시지는 무엇입니까? PlaceCollectionViewCell의 코드도 표시 할 수 있습니까? 스토리 보드에서 셀의 식별자를 "셀"로 설정했는지 확인하십시오. –

+0

이 줄에서 오류가 발생합니다. "cell.placeLabel.text = places [indexPath.row]" –

+0

PlaceCollectionViewCell에 대한 코드를 표시 할 수 있습니까? –

답변

1

...

는 nib 파일이 정의 셀에 사용되는지 확인 viewDidLoad에서이 행을 수행하여 collectionView와 제대로 연결됩니다.

constCollectionView.register(UINib(nibName:"PlaceCollectionViewCell", bundle:nil), forCellWithReuseIdentifier: "Cell") 
관련 문제