2016-09-14 11 views
6

呼ばれない問題「DrinkTransitioningDelegate」内Xcodeの8スウィフト3:モーダルプレゼンテーションは移行デリゲート

デリゲート関数が呼び出されません。 'td'インスタンスは、プレゼンテーションのライフサイクル中およびそのライフサイクルを超えてメモリに残ります。

class PresentingViewController: UIViewController { 

    let td = DrinkTransitioningDelegate() 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     let item = inventory.beverages[indexPath.row] 
     item.isSelected = true 
     let controller = DrinkViewController(item: item) 
     controller.delegate = self 
     controller.transitioningDelegate = td 
     controller.modalPresentationStyle = .custom 
     //let navCon = UINavigationController(rootViewController: controller) 
     //navCon.transitioningDelegate = td 
     //navCon.modalPresentationStyle = .custom 
     present(controller, animated: true) 
    } 

} 

class DrinkTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate { 

    func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? { 
     return DrinkPresentationViewController(presentedViewController:presented, presenting: presenting) 
    } 

    let animationController = DrinkAnimatedTransition() 

    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     animationController.isPresentation = true 
     return animationController 
    } 

    func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     animationController.isPresentation = false 
     return animationController 
    } 

    deinit { 
     print("adf") 
    } 

} 

質問はiOSの7 here

  • のために育てられた歴史

    • 質問はiOSの9 here
  • 答えて

    26

    ソリューション

    ために育てられました

    オプションのプロトコル機能は今や事実です。

    デリゲートは完全なオプション機能で構成されているため、警告はありません。

    これらの関数は、自分のカスタム関数としてコンパイラに表示されました。

    func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? { 
        return DrinkPresentationViewController(presentedViewController:presented, presenting: presenting) 
    } 
    
    let animationController = DrinkAnimatedTransition() 
    
    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        animationController.isPresentation = true 
        return animationController 
    } 
    
    func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        animationController.isPresentation = false 
        return animationController 
    } 
    

    これは正しい機能です。

    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { 
        return DrinkPresentationViewController(presentedViewController:presented, presenting: presenting) 
    } 
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        let animationController = DrinkAnimatedTransition() 
        animationController.isPresentation = true 
        return animationController 
    } 
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        let animationController = DrinkAnimatedTransition() 
        animationController.isPresentation = false 
        return animationController 
    } 
    
    関連する問題