S
S
Serg12122017-10-20 00:00:30
iOS
Serg1212, 2017-10-20 00:00:30

How to call dealloc in one controller?

The essence of the task:
there is a ViewController
It has a property view2 = UIView ()
in the viewDidLoad () method, I programmatically create dimensions for it and add it to the main view.
Question: how can the viewWillDisappear() and viewDidDisappear() methods be called in the same controller?
They after all come before and after removal.
Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Globak, 2017-10-20
@maximglobak

If I understood you correctly, then you need to close the UIViewController from within?
If so, you can try the method

func dismiss(animated flag: Bool, 
  completion: (() -> Void)? = nil)

This method tells the controller to "close". If you have a navigationController, then you can call the method
In such cases, the controller will close and fly out of memory, and in this case, the dealloc method will be called from it. Unless, of course, you have a strong link to it.

A
Alexander Tikhonov, 2017-10-20
@tikhonov666

viewWillDisappear()and viewDidDisappear()these are the view controller life cycle methods, these methods are called by the UIKit framework itself, manually, usually they are not called. They are called by the framework when the view of the controller is about to disappear and when it has disappeared, respectively, only after that the controller will be removed from memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question