2016-10-10 2 views
0

개발중인 앱을 변경해야하며 풀 타임 iOS 개발자가 아닙니다. 실행 있지만 (그들이 layoutAttributesForElementsinRect를 오버라이드 (override) 자신의 사용자 정의 UICollectionViewLayout에서 https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterestSwift의 UICollectionViewLayout에서 오류가있는 메소드를 오버라이드

하지만 난 엑스 코드 (8) 컴파일러에서 오류를 받고 있어요 : 나는 iOS 앱에 대한 인터페이스와 같은 클립을 얻으려고 여기 자습서를하고 있어요 Legacy Swift Language Version을 Yes로 설정).

내가 오류는 다음과 같습니다 Method does not override any method from its superclass

축약 된 코드는 다음과 같습니다

class PinterestLayout: UICollectionViewLayout { 

    .... 
    override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? { 

    var layoutAttributes = [UICollectionViewLayoutAttributes]() 

    // Loop through the cache and look for items in the rect 
    for attributes in cache { 
     if CGRectIntersectsRect(attributes.frame, rect) { 
     layoutAttributes.append(attributes) 
     } 
    } 
    return layoutAttributes 
    } 

나는 컴파일하지만 작동하지 않고 내가 재정의를 제거하면, 그것은 준다 비공개로 방법을 전환하는 경우 나 갈등. 기본 메서드를 재정의하고 싶지만이를 작동시키는 방법을 모르겠습니다.

답변

5

잘못된 서명이 있습니다. 이것은 실제로 override 키워드가 존재하는 이유입니다. 오버라이드가 자동으로 발생하지 않고 API 변경이 이러한 방식으로 감지되므로 문제를 진단하기가 어려워집니다.

이 언급 된 튜토리얼 코드가 스위프트 2.x를 통해 작성된 때문이다

override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? 
+0

하지 3.0 –

+0

@Ahmad 예, 그 근본 원인이다이어야한다. 'override' 키워드의 (지금) 오용으로 던져진 오류는 여러분이 그것을 잡을 수있는 증상입니다. – Alexander

+0

thx - 그게 문제였습니다. – timpone

관련 문제