我想在视图控制器的生命周期结束时执行一些清理,即删除NSNotificationCenter通知.dealloc在Swift编译器错误中实现结果:
Cannot override 'dealloc' which has been marked unavailable
Run Code Online (Sandbox Code Playgroud)
在Swift中对象生命结束时执行某些清理的首选方法是什么?
我正在创建一个ViewController对象,将其推送到导航控制器.当从堆栈弹出对象时 - 它没有被释放而Deinit没有被调用.可能是什么原因?
这是推送的代码:
self.navigationController?.pushViewController(CustomViewController(), animated: true)
Run Code Online (Sandbox Code Playgroud)
这是弹出的代码:
self.navigationController?.popViewControllerAnimated(true)
Run Code Online (Sandbox Code Playgroud) 我UISplitViewController每次点击Master VC中的一行时都会使用,我可以看到它viewDidLoad()在Detail VC中运行.
这是否意味着我每次点击都会创建一个新的Detail VC实例?
如果是这样,我如何检查Detail VC是否正确卸载并且我不只是创建越来越多的新Detail VC?
我在斯威夫特有点失落.以前我可以在dealloc()中使用NSLog并查看UIViewController正确的卸载.
我在这里Swift有一个deinit函数,但从未调用过:
deinit {
println("\(__FILE__.lastPathComponent)) : \(__FUNCTION__)")
NSNotificationCenter.defaultCenter().removeObserver(self)
}
Run Code Online (Sandbox Code Playgroud)
1)我应该把我的观察员移到哪里?
2)当我查看Xcode中的Debug Navigator时,内存使用率一直在上升而且从不下降.
if segue.identifier == "addEvent" {
if let controller = (segue.destinationViewController as UINavigationController).topViewController as? ManageViewController {
controller.manageEvent = nil
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
Run Code Online (Sandbox Code Playgroud)
我没有做过与我见过的很多例子不同的事情,但我担心deinit没有被召唤
deinit正在工作 - 问题是委托停止被调用(见下面的答案)我原来的非工作代码是:
protocol ManageViewDelegate {
func pressedButton(sender: AnyObject)
}
class ManageView: UIView {
var delegate: ManageViewDelegate? = nil
...
} …Run Code Online (Sandbox Code Playgroud)