0
의 UIViewController에서 UICollectionViewCell

변경 항목이 같은 선언 UICollectionViewCell

내에서 특정 항목의 크기를 변경하기 위해 노력하고있어

내부 크기 :

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.CellIdentifier, for: indexPath) as! NameCollectionViewCell 

    if(retreivedEvents == nil) { 
    // print("data not received yet...") 
     return cell 
    } else { 
    // print("new data given") 
     cell.anEvent = self.retreivedEvents![indexPath.row] 
     cell.setNeedsLayout() 
     return cell 
    } 
} 

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { 

    let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.CellIdentifier, for: indexPath) as! NameCollectionViewCell 

    let screenHeigh = UIScreen.main.bounds.size.height 

    cell2.frame.size.height = cellSize * 0.8 
    cell2.descriptionTextView.frame.size.height += 50 
    cell2.theImageView.frame.size.height = cellSize * 0.8 

    let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout 
    layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10) 
    return CGSize(width: self.collectionView.frame.width,height:cell2.frame.size.height) 
} 

문제 : 때마다 나는 그것을 실행하면 콘솔이 표시됩니다

ty의 캐치되지 않는 예외로 종료 pe NSException

. 나는 그 오류가 무엇인지 모르겠다.

enter image description here

+0

정보를 더 공유 할 수 있습니까? 앱이 어디에서 충돌했는지 (코드 줄)? –

+0

@JimmyJames 안녕하세요, 네. AppDelegate.swift 안에 있습니다. *** 캐치되지 않은 예외 'NSRangeException'으로 인한 응용 프로그램 종료, 이유 : '*** - [NSArrayM objectAtIndex :] : 경계 1을 넘어서는 색인 1' – WoShiNiBaBa

+0

디버그를 위해 예외 브레이크 포인트 배치 –

답변

0

는 지금, 나는 100 % 아니에요하지만 난 sizeForItem 내부의 특정 인덱스 경로 셀을 대기열에서 매우 조심해야합니다. 셀 인스턴스를 사용하여 크기를 계산하지만 컬렉션보기에서 이미 사용중인 셀 인스턴스는 사용하지 않으려합니다. forIndexPath을 사용하지 않는 대기열에 포함되지 않는 메서드를 사용하여이를 피할 수 있습니다.