iOS Developer
easyios-view-controller-lifecycle
Explain the UIViewController lifecycle and common pitfalls.
Answer
Key lifecycle methods include `viewDidLoad`, `viewWillAppear`, `viewDidAppear`, and their disappearing counterparts.
Pitfalls:
- Starting heavy work on the main thread in `viewDidLoad`
- Duplicating network calls in `viewWillAppear`
- Not cancelling tasks on disappearance
A good pattern is to start one-time setup in `viewDidLoad` and refresh lightweight UI state in `viewWillAppear`.
Related Topics
iOSUIKitLifecycle