2016-09-18 3 views
2

내 뷰 컨트롤러를 소스 테이블로 테이블 뷰에 등록하여 앱에서 3D 터치를 구현했습니다. 그리고 그것을 구현 한 이후 지난 2 주 동안 잘 작동했습니다.3D 터치 뷰 컨트롤러가 호출되지 않습니다.

하지만 방금 시도한 결과 더 이상 작동하지 않는 것으로 나타났습니다. 그 코드를 건드리지 않았으므로 문제가 무엇인지 알지 못합니다.

보기 컨트롤러가 UIViewControllerPreviewing에 확실히 등록되어 있지만 previewingContext(previewingContext: viewControllerForLocation:)은 호출되지 않습니다.

미리보기를 위해 등록기와 별도로 설정해야 할 일이 무엇인지 모르겠지만 그 방법을 트리거하는 것으로 보이는 것은 없습니다. 3D 터치가 잘 작동하는 것처럼 보이는 별도의보기 컨트롤러가 있지만 다르게는하지 않습니다.

아무에게도 메서드가 호출되지 않는 이유에 대한 아이디어가 있습니까? 이전에 잘 작동했기 때문에 작업이 중단 된 것 같아서 정말 실망 스럽습니다. 감사. 여기

previewingContext(previewingContext: viewControllerForLocation:) 메서드에 대한 코드입니다 :

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { 

    let identifier = "ClipPlayerViewController" 

    guard let indexPath = tableView.indexPathForRowAtPoint(location), let destination = storyboard?.instantiateViewControllerWithIdentifier(identifier) as? ClipPlayerViewController else { return nil } 

    let effect = filteredEffectsSortedBySection[indexPath.section].effects[indexPath.row] 

    switch effect.mediaType { 
    case .Video: 
     destination.effect = effect 

     destination.showsPlaybackControls = false 

     if let thumbnail = thumbnailsForEffects[effect], let unwrappedThumbnail = thumbnail { 
      destination.preferredContentSize = CGSizeMake(unwrappedThumbnail.size.width - 2, unwrappedThumbnail.size.height - 2) 
     } else if let effectSize = destination.player?.currentItem?.asset.tracksWithMediaType(AVMediaTypeVideo).first?.naturalSize { 
      destination.preferredContentSize = effectSize 
     } 

     previewingContext.sourceRect = tableView.cellForRowAtIndexPath(indexPath)!.frame 

     return destination 

    case .Texture: 
     return nytPhotosViewControllerForEffectAtIndexPath(indexPath) 
    } 
} 

그리고 여기 viewDidLoad()에서 호출 내가 미리 등록 코드입니다 :

당신이 Swift3로 업그레이드 했
if traitCollection.forceTouchCapability == .Available {   
    registerForPreviewingWithDelegate(self, sourceView: tableView) 
} 

답변

0

은? 그렇다면 델리게이트 함수 params가 일치하는지 확인하십시오.

또한 registerForPreviewing이 제대로 호출되는지 확인해야합니다.

registerForPreviewing(with: self as! UIViewControllerPreviewingDelegate, sourceView: view) 
+0

고마워,하지만 그 프로젝트에서 아직 스위프트 3으로 업데이트하지 않았다. (아직이 문제가 무엇인지 알아 내지 못했다.) – CompC

+0

아 맞다. viewControllerForLocation 대리자 함수를 공유하면 작동하는 버전으로 확인할 수 있습니다. –

+0

원본 코드에 내 코드를 추가했습니다. – CompC

0

스위프트 3 마이그레이션 도구를 실행합니다. (편집> 변환> 현재 신속 구문으로)

Swift 3 컴파일러를 사용하고있는 것 같습니다. Swift 2에서 여전히 작동하는 경우 (예 : registerForPreviewing(with:sourceView:)tableView.cellForRow(at:)) 작동하지 않는 메서드 호출이 컴파일되지 않습니다. 그 이유는 이들 API에 대한 Swift 3 구문 때문입니다.

func previewingContext(_ previewingContext: UIViewControllerPreviewing, 
    viewControllerForLocation location: CGPoint) -> UIViewController? 
: 밑줄이 첫 번째 매개 변수에 인수를 라벨이 없다는 것을 나타내는주의, 그래서 당신의 선언과 같아야합니다 - Migrator를 그것을 잡으려고 실패하면

, 대리자 방법에 대한 스위프트 3 메소드 서명은 previewingContext(_:viewControllerForLocation:)입니다

+0

네 말이 맞아. 그것은 Swift 3으로 업데이트하려고했던 구버전에서 나온 것이지만, 사용하고있는 CocoaPod의 일부에 약간의 문제가있었습니다. 실제로 빌드되는 프로젝트의 버전은 Swift 2.3입니다. 원래의 게시물을 업데이트하여 실제로 현재 사용중인 코드를 표시합니다 (Swift 2.3에서 마이그레이션은 여전히 ​​포드와 관련된 문제를 나타냅니다) – CompC

관련 문제