问题标签 [deinit]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
swift - 取消初始化呈现的视图控制器
我有下一个功能
我在呈现的视图控制器中使用它,例如在 PresentedViewController 中。
但是当我切换到所需的视图控制器时,我呈现的视图控制器不会取消初始化。我必须使用这种方式,首先解雇:
而不是简单
ios - 当视图控制器消失时会调用 deinit 吗?
我创建了两个视图控制器,例如
(2) View Controller 中有一个按钮,单击该按钮将显示 (3) Details View Controller。我已经创建了一个从按钮到 (3) VC 的 segue。
我deinit
在这两个类中添加了块。
但是,这不会被记录。视图控制器何时会被释放?
swift - deinit 末尾的 Defer 语句会产生警告
自Xcode 10.2 (Swift 5)起,作用域defer
末尾的语句产生:deinit
作用域结束前的“defer”语句总是立即执行;替换为“do”语句以消除此警告
让我们看一下这个例子:
- 当然,可以通过将代码从观察者移动到方法并显式调用它来消除此警告,但是……</li>
这个警告有什么意义?defer
- 将声明放在 中是否合理deinit
?(例如,能够触发属性的观察者)。
swift - 斯威夫特:一些类没有取消初始化
在以下代码中NSString
,并且NSNumber
在删除引用时不会取消初始化。NSMutableString
并且NSAttributedString
被取消初始化。deinit 的标准是什么?
输出 :
ios - 如何取消初始化子 UIViewController?
我有几个UIViewController
s 添加到内容视图中。调用我的 remove 函数后,我注意到 childUIViewController
的deinit
函数没有被调用,除非我明确地将 child 的值设置UIViewController
为nil
.
这是正确的行为还是我做错了什么?
ios - swift deinit方法没有调用
在UIViewController
deinit
方法中没有在 ios swift4.2 中调用
我已经尝试了下面的代码,以便在未调用方法中导航viewController
后导航到下一个。popToViewcontroller
deinit
推送视图:
上面的deinit
方法应该被调用popToViewcontroller
swift - 如何取消嵌入 TabBarController [Swift 5] 中的 ViewControllers
我在 TabBarController 中封装并实例化了两个 ViewController。TabBarController 在上级 NavigationController 中实例化。
当 NavigationController 决定返回并“离开”TabBarController 及其两个 ViewController 时,NavigationController 会取消 TabBarController。调用 TabBarController 的 deinit 方法。但我注意到,我的两个 ViewController 的 deinit 方法没有被调用。
问题
怎么可能是 TabBarController 可以被释放,但嵌入的 ViewController 不能?ARC 在这种情况下如何工作?如何强制嵌入式 ViewControllers 的 deinit 调用?
ios - Swift - 执行 segue 时视图控制器不会取消初始化
我对内存管理和 ARC 的整个概念相当陌生。
我最近研究了它,发现成功参半。
首先应该注意的是,有些 ViewController
确实会取消初始化,但我仍在学习和清理我的应用程序。
但是,我注意到的一个常见模式是,当我使用该行时,如果没有强引用,navigationController?.popViewController(animated: true)
这实际上是一个视图控制器。deinit
但是,我的问题是,当我使用 segue 并使用performSegue(withIdentifier: "showDetail_Segue", sender: nil)
该deinit
方法时,永远不会使用/调用该方法。(我只有一个打印语句来指示视图是否已被取消初始化)。在大多数情况下,当我执行 segue 时,我将数据传递给另一个视图控制器,因此,我使用以下函数override func prepare(for segue: UIStoryboardSegue, sender: Any?) {}
。
我试图将我的 segue 更改为navigationController?.pushViewController(VC, animated: true)
但我的应用程序崩溃了。
我在这里错过了什么吗?
以编程方式执行时也不会ViewControllers
取消初始化。navigationController
popped
segue
有人可以告诉我我做错了什么吗?
谢谢你。
ios - Swift - 使用条件展开/执行 Segue 取消初始化视图
我UINavigationController
在我的应用程序中使用 a 。我正在尽力管理内存分配。如果没有强引用,我所有的视图都确实有一个在执行ordeinit
时调用/打印的方法。unWindSegue
navigationController.popViewController()
使用时performSegueWithIdentifer
,从不调用/使用override func prepare(for segue: UIStoryboardSegue, sender: Any?)
该deinit
方法。我认为这是由于我正在过渡到的视图不在内存中。
执行segue时是否可以有条件语句?加载我的应用程序后,它就HomeView
在内存中。而且我还可以放松到它允许释放当前视图。
我有几个观点,我希望尽可能地管理内存。是否可以peformSegueWithIdentifier
通过使用条件语句一次且始终展开到视图,一旦它在内存中?
伪代码:
还是有另一种方法可以解决这个问题,无论视图是否在内存中,都可以在执行 segue 时释放内存?我的应用程序基于时间和最新信息,我最不想做的就是返回旧/冗余数据。
我对内存管理相当陌生,所以如果这个问题看起来有点白痴,我深表歉意。
ios - Swift closure is still in memory after VC deinit is called
I have a bluetooth class which passes when a char value is updated to a closure in a view controller (as well as the same closure in a singleton class). when the VC deinit is called, the closure in the VC is still being executed when the char value is updated. I am using [weak self] for the closure in the VC. I'd like to be able to stop this VC closure from being called when the view is deinitialised. But I also don't understand why the other callback in the singleton is not being executed after the VC is presented!
Included below is the syntax for the closure inside the VC