问题
“DrinkTransitioningDelegate”中的委托(delegate)函数未被调用。 “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")
}
}
历史
最佳答案
解决方案
可选的协议(protocol)函数现在很重要。
委托(delegate)完全由可选函数组成,因此没有警告。
这些函数作为我自己的自定义函数出现在编译器中。
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
}
关于ios - Xcode 8 swift 3 : Modal presentation transitioning delegate not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497771/