diff --git a/AsyncDisplayKit/ASCellNode.h b/AsyncDisplayKit/ASCellNode.h index 4debef7505..b89574983f 100644 --- a/AsyncDisplayKit/ASCellNode.h +++ b/AsyncDisplayKit/ASCellNode.h @@ -93,17 +93,6 @@ typedef NSUInteger ASCellNodeAnimation; */ - (void)setNeedsLayout; -/** - * @abstract Initializes a cell with a given viewControllerBlock. - * - * @param viewControllerBlock The block that will be used to create the view controller whose root view will be used to create the backing view. - * - * @return An ASCellNode created using the root view of the view controller provided by the viewControllerBlock. - * The view controller's root view is resized to match the calcuated size produced during layout. - * - */ -- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock; - /** * @abstract Initializes a cell with a given viewControllerBlock. * diff --git a/AsyncDisplayKit/ASCellNode.m b/AsyncDisplayKit/ASCellNode.m index bc2159c066..f757f863ed 100644 --- a/AsyncDisplayKit/ASCellNode.m +++ b/AsyncDisplayKit/ASCellNode.m @@ -18,10 +18,11 @@ #pragma mark - #pragma mark ASCellNode -@interface ASCellNode (){ +@interface ASCellNode () +{ ASDisplayNodeDidLoadBlock _nodeLoadedBlock; - ASDisplayNode *_viewControllerNode; UIViewController *_viewController; + ASDisplayNode *_viewControllerNode; } @end @@ -40,11 +41,6 @@ return self; } -- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock -{ - return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil]; -} - - (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock { if (!(self = [super init])) @@ -52,21 +48,40 @@ ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController"); - _viewController = viewControllerBlock(); + if (viewControllerBlock) { + _viewController = viewControllerBlock(); + + __weak UIViewController *weakViewController = _viewController; + _viewControllerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{ + return weakViewController.view; + } didLoadBlock:didLoadBlock]; + + [self addSubnode:_viewControllerNode]; + _nodeLoadedBlock = didLoadBlock; + } - _viewControllerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{ - return _viewController.view; - } didLoadBlock:didLoadBlock]; - - [self addSubnode:_viewControllerNode]; - - _nodeLoadedBlock = didLoadBlock; return self; } -- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { - _viewControllerNode.frame = (CGRect){{0,0}, constrainedSize.max}; - return [super layoutSpecThatFits:constrainedSize]; +//- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize +//{ +// _viewControllerNode.frame = (CGRect){{0,0}, constrainedSize.max}; +// NSLog(@"%f %f", constrainedSize.max.width, constrainedSize.max.height); +// return [super layoutSpecThatFits:constrainedSize]; +//} + +- (void)layout +{ + [super layout]; + + _viewControllerNode.frame = self.bounds; +} + +- (void)layoutDidFinish +{ + [super layoutDidFinish]; + + _viewControllerNode.frame = self.bounds; } - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock @@ -135,7 +150,8 @@ #pragma mark - #pragma mark ASTextCellNode -@interface ASTextCellNode () { +@interface ASTextCellNode () +{ NSString *_text; ASTextNode *_textNode; } diff --git a/examples/CollectionViewWithViewControllerCells/Sample.xcodeproj/project.pbxproj b/examples/CollectionViewWithViewControllerCells/Sample.xcodeproj/project.pbxproj index 50dad6fd59..a93761d93a 100644 --- a/examples/CollectionViewWithViewControllerCells/Sample.xcodeproj/project.pbxproj +++ b/examples/CollectionViewWithViewControllerCells/Sample.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 25A1FA851C02F7AC00193875 /* MosaicCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 25A1FA841C02F7AC00193875 /* MosaicCollectionViewLayout.m */; }; - 25A1FA881C02FCB000193875 /* ImageCellNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 25A1FA871C02FCB000193875 /* ImageCellNode.m */; }; 9B92C8811BC17D3000EE46B2 /* SupplementaryNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B92C8801BC17D3000EE46B2 /* SupplementaryNode.m */; }; 9BA2CEA11BB2579C00D18414 /* Launchboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9BA2CEA01BB2579C00D18414 /* Launchboard.storyboard */; }; AC3C4A641A11F47200143C57 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AC3C4A631A11F47200143C57 /* main.m */; }; @@ -22,8 +21,6 @@ /* Begin PBXFileReference section */ 25A1FA831C02F7AC00193875 /* MosaicCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MosaicCollectionViewLayout.h; sourceTree = ""; }; 25A1FA841C02F7AC00193875 /* MosaicCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MosaicCollectionViewLayout.m; sourceTree = ""; }; - 25A1FA861C02FCB000193875 /* ImageCellNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCellNode.h; sourceTree = ""; }; - 25A1FA871C02FCB000193875 /* ImageCellNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCellNode.m; sourceTree = ""; }; 2DBAEE96397BB913350C4530 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 9B92C87F1BC17D3000EE46B2 /* SupplementaryNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SupplementaryNode.h; sourceTree = ""; }; 9B92C8801BC17D3000EE46B2 /* SupplementaryNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SupplementaryNode.m; sourceTree = ""; }; @@ -90,8 +87,6 @@ AC3C4A661A11F47200143C57 /* AppDelegate.m */, AC3C4A681A11F47200143C57 /* ViewController.h */, AC3C4A691A11F47200143C57 /* ViewController.m */, - 25A1FA861C02FCB000193875 /* ImageCellNode.h */, - 25A1FA871C02FCB000193875 /* ImageCellNode.m */, AC3C4A8D1A11F80C00143C57 /* Images.xcassets */, AC3C4A611A11F47200143C57 /* Supporting Files */, 9B92C87F1BC17D3000EE46B2 /* SupplementaryNode.h */, @@ -249,7 +244,6 @@ AC3C4A671A11F47200143C57 /* AppDelegate.m in Sources */, AC3C4A641A11F47200143C57 /* main.m in Sources */, AEE6B3E51C16B65600238D20 /* ImageViewController.m in Sources */, - 25A1FA881C02FCB000193875 /* ImageCellNode.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/examples/CollectionViewWithViewControllerCells/Sample/ImageCellNode.h b/examples/CollectionViewWithViewControllerCells/Sample/ImageCellNode.h deleted file mode 100644 index d2722d19d2..0000000000 --- a/examples/CollectionViewWithViewControllerCells/Sample/ImageCellNode.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ImageCellNode.h -// Sample -// -// Created by McCallum, Levi on 11/22/15. -// Copyright (c) 2015 Facebook. All rights reserved. -// - -#import - -@interface ImageCellNode : ASCellNode - -- (instancetype)initWithImage:(UIImage *)image; - -@end diff --git a/examples/CollectionViewWithViewControllerCells/Sample/ImageCellNode.m b/examples/CollectionViewWithViewControllerCells/Sample/ImageCellNode.m deleted file mode 100644 index a25b61cc07..0000000000 --- a/examples/CollectionViewWithViewControllerCells/Sample/ImageCellNode.m +++ /dev/null @@ -1,45 +0,0 @@ -// -// ImageCellNode.m -// Sample -// -// Created by McCallum, Levi on 11/22/15. -// Copyright (c) 2015 Facebook. All rights reserved. -// - -#import "ImageCellNode.h" -#import "ImageViewController.h" - -@implementation ImageCellNode { - ASImageNode *_imageNode; -} - -//- (id)initWithImage:(UIImage *)image -//{ -// self = [super init]; -// if (self != nil) { -// _imageNode = [[ASImageNode alloc] init]; -// _imageNode.image = image; -// [self addSubnode:_imageNode]; -// } -// return self; -//} - -- (id)initWithImage:(UIImage *)image -{ - return [self initWithViewControllerBlock:^UIViewController *{ - return [[ImageViewController alloc] initWithImage:image]; - }]; -} - -- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize -{ - [_imageNode measure:constrainedSize]; - return constrainedSize; -} - -- (void)layout -{ - _imageNode.frame = CGRectMake(0, 0, _imageNode.calculatedSize.width, _imageNode.calculatedSize.height); -} - -@end diff --git a/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m b/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m index fc0991458d..36f0ef5011 100644 --- a/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m +++ b/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m @@ -94,7 +94,10 @@ static NSUInteger kNumberOfImages = 14; { ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController *{ return [[ImageViewController alloc] initWithImage:_sections[indexPath.section][indexPath.item]]; - }]; + } didLoadBlock:nil]; + + node.layer.borderWidth = 1.0; + node.layer.borderColor = [UIColor blackColor].CGColor; return node; }