问题
不调用'DrinkTransitioningDelegate'中的委托函数.'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")
}
}
Run Code Online (Sandbox Code Playgroud)
历史
小智 34
解
可选的协议功能现在是一个东西.
委托完全由可选功能组成,因此没有警告.
这些函数在编译器中显示为我自己的自定义函数.
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
}
Run Code Online (Sandbox Code Playgroud)
这些是正确的功能.
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7791 次 |
| 最近记录: |