From 85ef60caaa5df7c0b0e5a1779be7bbcbb0a9da2e Mon Sep 17 00:00:00 2001 From: Hannah Troisi Date: Mon, 18 Apr 2016 22:47:13 -0700 Subject: [PATCH] Update containers-asviewcontroller.md --- _docs/containers-asviewcontroller.md | 51 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/_docs/containers-asviewcontroller.md b/_docs/containers-asviewcontroller.md index 9cb46424..5c30f964 100755 --- a/_docs/containers-asviewcontroller.md +++ b/_docs/containers-asviewcontroller.md @@ -5,39 +5,40 @@ permalink: /docs/containers-asviewcontroller.html next: containers-astablenode.html --- -`ASViewController` is a subclass of `UIViewController` and adds the following features - +`ASViewController` is a subclass of `UIViewController` that adds several useful features for hosting `ASDisplayNode` hierarchies. An `ASViewController` can be used in place of any `UIViewController` - including within a `UINavigationController`, `UITabBarController` and `UISpitViewController` or as a modal view controller. -An `ASViewController` can be used in place of any `UIViewController` - including within a `UINavigationController`, `UITabBarController` and `UISpitViewController` or as a modal view controller. +One of the main benefits to using an `ASViewController` is to save memory. An `ASViewController` 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. More features will be added over time, so it is a good idea to base your view controllers off of this class. -###Porting UIViewControllers to ASViewControllers### A `UIViewController` provides a view of its own. An `ASViewController` is assigned a node to manage in its designated initializer `initWithNode:`. -Consider the following ASViewController subclass that would like to use a custom table node as its managed node. - +Consider the following (abbreviated) `ASViewController` subclass from the ASDKgram sample app that would like to use a table node as its managed node. This table node is assigned to the `ASViewController` in its `initWithNode:` designated initializer method. ``` -- (instancetype)initWithModel:(NSArray *)models +@interface PhotoFeedNodeController : ASViewController +@end + +@interface PhotoFeedNodeController () +@end + +@implementation PhotoFeedNodeController { - ASTableNode *tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain]; + ASTableNode *_tableNode; +} - if (!(self = [super initWithNode:tableNode])) { return nil; } - - self.models = models; - - self.tableNode = tableNode; - self.tableNode.dataSource = self; - - return self; +- (instancetype)init +{ + _tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain]; + self = [super initWithNode:_tableNode]; + + if (self) { + _tableNode.dataSource = self; + _tableNode.delegate = self; + } + + return self; } ``` -For a full guide on porting your UIKit app to ASDK see Porting Your App (INCLUDE LINK). - -###Example Apps### - - - +
+If your app already has a complex view controller hierarchy, it is perfectly fine to have all of them subclass `ASViewController`. That is to say, even if you don't use `ASViewController`'s designated initializer `initiWithNode:`, and only use the `ASViewController` 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. +