Xcode 8 Swift 3:模态演示文稿转换委托不被调用
问题
“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") } }
历史
- 这里提出了iOS 7的问题
- 这里提出了iOS 9的问题
解
可选的协议function现在是一件事情。
代表完全由可选function组成,所以没有警告。
这些函数在编译器中显示为我自己的自定义函数。
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 }
这些是正确的function。
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 }
- 如何使用Mapbox实现转弯导航
- Swift的计算属性不能在init中使用?
- 在iOS应用程序启动时有条件地切换根视图控制器的最佳方式
- Swift:用户位置附近的Geofencing / geolocations
- 覆盖AVMetadataMachineReadableCodeObject的stringValue属性或创build一个替代scheme,输出二进制数据
- 如何使用平移手势使用四元数在SceneKit中旋转摄像机
- UIPopoverPresentationController以全屏显示popup窗口
- UICollectionViewFlowLayout minimumLineSpacing不适用于整个集合视图 – Swift
- UITableView – 上一节的页脚滚动屏幕底部。 如何预防?