2016-09-14 22 views
6

Issue chức năngXcode 8 Swift 3: phương thức trình bày đang chuyển đổi đại biểu không được gọi

Các đại biểu trong 'DrinkTransitioningDelegate' không được gọi. Ví dụ 'td' vẫn còn trong bộ nhớ trong và ngoài vòng đời của bản trình bày.

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") 
    } 

} 

Lịch sử

  • Câu hỏi đã được nêu ra cho iOS 7 here
  • Câu hỏi đã được nêu ra cho iOS 9 here

Trả lời

26

Giải pháp

Chức năng giao thức tùy chọn hiện là một điều.

Đại biểu bao gồm các chức năng tùy chọn hoàn toàn, do đó không có cảnh báo.

Các chức năng này xuất hiện với trình biên dịch làm chức năng tùy chỉnh của riêng tôi.

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 
} 

Đây là những chức năng chính xác.

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 
} 
Các vấn đề liên quan