我有settingsController
,这是一个自定义UINavigationController
,必须出现和消失。
它的XIB在故事板中,由于其他管家的目的,我必须使用var settingsController
来跟踪它。
主视图控制器:
class MainViewController: UIViewController {
var settingsController : MySettingsNavigationController?
func settingsButtonPressed () {
let storyboard = UIStoryboard(name: "Main Storyboard", bundle: nil)
self.settingsController = storyboard.instantiateViewController(withIdentifier: "Settings Navigation Controller") as? MySettingsNavigationController
self.settingsController!.transitioningDelegate = self
self.settingsController!.modalPresentationStyle = .custom
self.present(self.settingsController!, animated: true, completion: nil)
}
//Settings View Controller Transition Methods
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)
let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)
if(self.isSettingsPresenting == true) {
toViewController!.view.alpha = 1;
toViewController!.view.transform = CGAffineTransform(scaleX: 0.001, y: 0.001);
toViewController!.view.center = self.settingsButton.center
UIView.animate(withDuration: 0.5, delay: 0,
options: [.curveEaseIn], animations: { () -> Void in
toViewController!.view.alpha = 1;
toViewController!.view.transform = CGAffineTransform(scaleX: 1, y: 1);
toViewController!.view.center = fromViewController!.view.center
containerView.addSubview(toViewController!.view)
}, completion: { (completed) -> Void in
transitionContext.completeTransition(completed)
})
} else {
UIView.animate(withDuration: 0.5, delay: 0,
options: [.curveEaseOut], animations: { () -> Void in
fromViewController!.view.alpha = 0;
fromViewController!.view.transform = CGAffineTransform(scaleX: 0.01, y: 0.01);
fromViewController!.view.center = self.settingsButton.center
}, completion: { (completed) -> Void in
//Two lines below added later to test..
fromViewController?.view.removeFromSuperview()
fromViewController?.removeFromParentViewController()
transitionContext.completeTransition(completed)
})
}
}
}
设置导航控制器:
class MySettingsNavigationController: UINavigationController, UINavigationControllerDelegate
{
.....
func closeButtonPressed (_ sender: UIButton!) {
self.dismiss(animated: true, completion: {
//Tried removing self in here...
})
}
}
问题:
当我调出settingsController
并关闭它时,settingsController
分配的内存永远不会释放;不知何故,settingsController
没有被解除分配。
注意:
不知怎的,我必须:
UINavigationControllerDelegate
了。这本来可以
我有机会回电给父母,MainViewController
就是这样
准备好被删除答案 0 :(得分:3)
不知何故,settingsController没有被取消分配
var settingsController
看起来像是可能的罪魁祸首
持有ViewController
作为var
对象非常气馁。我必须使用' var settingsController'来跟踪它。由于其他管家的目的。
sharedHelper
相关属性数据的controller
- esque类进行评估,或处理用户互动。settingsButtonPressed
(单独应该负责调用settingsController
)之外,没有任何函数可以设计为需要settingsController
的实例才能执行。此类函数所需的数据可通过多种方式提取,如protocols
,blocks
,shared instances
等。