2016-11-06 9 views
1

문제휴식을 취하가 트리거되지 SEGUE

내 문제는 언 와인드 프로세스가 뒤로 단추를 클릭 할 경우에도 트리거되지 않는 것입니다.

내 코드

나는 2ndViewController에 사용자 정의 SEGUE를 사용하는 클래스 1stViewController 있습니다. 내 2ndViewController에서

override func perform() { 
    let sourceVC = self.source as! 1stViewController 
    let destinationVC = self.destination as! 2ndViewController 
    sourceVC.addChildViewController(destinationVC) 
    sourceVC.view.addSubview(destinationVC.view) 
} 

난 다시 1stViewController에 풀기 SEGUE를 트리거 버튼을 추가 한 : 사용자 정의 SEGUE는 다음과 같습니다. unwinding segue는 2ndViewController의 unwind segue triggering exit 식별자를 통해 연결됩니다. 언 와인드 SEGUE 출구가 연결된 따라서, I는 IBAction를 생성했다 :

I 버튼의 동작 기능에 사용되는 것과 동일한 풀림 SEGUE의 식별자를 설정
@IBAction func unwindToFeed(segue: UIStoryboardSegue) {} 

func handleActionBackButton(){ 
    print("here") 
    self.performSegue(withIdentifier: "unwindId", sender: self) 
} 

"여기"는 버튼을 클릭 할 때 인쇄되지만 performSegue는 그렇지 않은 것처럼 보입니다.

나는 나뿐만 아니라 사용자 정의 unwindSegue 클래스를 필요가 있다고 추측, 그래서 나는 unwindSegueEventToFeed 생성 :

class unwindSegueEventToFeed: UIStoryboardSegue { 

override func perform() { 
    let sourceVC = self.source as! 2ndViewController 
    let destinationVC = self.destination as! 1stViewController 

    let sourceView = sourceVC.view as UIView! 
    let destView = destinationVC.view as UIView! 

    let window = UIApplication.shared.keyWindow 
    window?.insertSubview(destView!, aboveSubview: sourceView!) 
    sourceVC.dismiss(animated: false, completion: nil) 
} 

} ... 2ndViewController에서 호출됩니다

override func segueForUnwinding(to toViewController: UIViewController, from fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue? { 
    return unwindSegueEventToFeed(identifier: identifier, source: fromViewController, destination: toViewController) 
} 

모든 단서에를 풀어내는 과정을 시작하기 위해 내가해야 할 일은 무엇입니까?

+0

그냥 확인하려면 'unwindToFeed'가 1stViewController에 있습니까? – Paulw11

+0

unwindToFeed가 2ndViewController에 있습니다. –

+0

그 위치가 잘못되었습니다.unwind 메소드가 풀려있는 뷰 컨트롤러에서 * – Paulw11

답변

1

나는 이런 식으로 당신의 모범을 보았습니다. ViewController는 첫 번째 뷰 컨트롤러입니다. unwindToFeed이다 (그리고 여야 함)한다는

class ViewController: UIViewController { 
    @IBAction func unwindToFeed(_ segue: UIStoryboardSegue) { 
     let child = self.childViewControllers[0] 
     child.willMove(toParentViewController: nil) 
     child.view.removeFromSuperview() 
     child.removeFromParentViewController() 
    } 
} 

class MySegue: UIStoryboardSegue { 
    override func perform() { 
     let sourceVC = self.source as! ViewController 
     let destinationVC = self.destination as! ViewController2 
     sourceVC.addChildViewController(destinationVC) 
     sourceVC.view.addSubview(destinationVC.view) 
     destinationVC.view.frame = sourceVC.view.bounds 
     destinationVC.view.autoresizingMask = [.flexibleHeight, .flexibleWidth] 
     destinationVC.didMove(toParentViewController: sourceVC) 
    } 
} 

class ViewController2 : UIViewController { 
} 

참고 뷰 컨트롤러 : ViewController2 번째 뷰 컨트롤러이다. 두 번째보기 컨트롤러가 소스이고 대상이 아닌이 아니므로 두 번째보기 컨트롤러에 넣는 것은 의미가 없습니다.

지금은이 문제와 내 대답에 대한 몇 가지 의견을 싶습니다

  • 이 아이폰 OS 10 예이다. segueForUnwinding이 아니며 iOS 10에서는이라고 부릅니다. iOS 8 이후에 버려졌고 이후에 사용되지 않습니다.

  • segueForUnwinding의 iOS 9/10은 unwind(for:towardsViewController:)입니다. 구현하려고 시도했지만 ViewController2가 아니라 ViewController2에서 호출 된 것을 발견했습니다. 나는 그것을 iOS 10의 버그로 간주하고 그것을 Apple에보고하고 있습니다.

+0

하지만 내 예제는 iOS 9에서 전혀 작동하지 않는다. 일반적으로 사용자 정의 상위 뷰 컨트롤러로 unwind segues를 사용하는 전체적인 개념은 여전히 ​​매우 부서져 보인다. 그것이 수년간 계속되어 왔기 때문에 나는 그것을 완전히 피할 것을 제안 할 것입니다. – matt