Files
Texture/docs/_docs/containers-asdkviewcontroller.md
Joe Ferrucci e88783e920 Docs: Fix references of ASViewController/ASNavigationController (non-existent) to ASDKViewController/ASDKNavigationController (#2072)
* Fix references of ASViewController (non-existent) to ASDKViewController

* More references changes to old ASViewController

* Also update ASNavigationController -> ASDKNavigationController
2023-04-05 11:30:08 -07:00

3.1 KiB
Executable File

title, layout, permalink, prevPage, nextPage
title layout permalink prevPage nextPage
ASDKViewController docs /docs/containers-asdkviewcontroller.html asrunloopqueue.html containers-asnodecontroller.html

ASDKViewController is a subclass of UIViewController that adds several useful features for hosting ASDisplayNode hierarchies.

An ASDKViewController can be used in place of any UIViewController - including within a UINavigationController, UITabBarController and UISplitViewController or as a modal view controller.

Benefits of using an ASDKViewController:

  1. Save Memory. An ASDKViewController that goes off screen will automatically reduce the size of the fetch data and display ranges of any of its children. This is key for memory management in large applications.
  2. ASVisibility Feature. When used in an ASDKNavigationController or ASTabBarController, these classes know the exact number of user taps it would take to make the view controller visible.

More features will be added over time, so it is a good idea to base your view controllers off of this class.

Usage

A UIViewController provides a view of its own. An ASDKViewController is assigned a node to manage in its designated initializer -initWithNode:.

Consider the following ASDKViewController subclass, PhotoFeedNodeController, from the ASDKgram example project that would like to use a table node as its managed node.

This table node is assigned to the ASDKViewController in its -initWithNode: designated initializer method.

SwiftObjective-C
- (instancetype)init
{
  _tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain];
  self = [super initWithNode:_tableNode];

if (self) { _tableNode.dataSource = self; _tableNode.delegate = self; }

return self; }

init(models: [Model]) {
  let tableNode = ASTableNode(style: .plain)

  super.init(node: tableNode)

  self.models = models
  
  self.tableNode = tableNode
  self.tableNode.delegate = self
  self.tableNode.dataSource = self
}

Conversion Tip: If your app already has a complex view controller hierarchy, it is perfectly fine to have all of them subclass ASDKViewController. That is to say, even if you don't use ASDKViewController's designated initializer -initWithNode:, and only use the ASDKViewController in the manner of a traditional UIViewController, this will give you the additional node support if you choose to adopt it in different areas your application.