1

I am using Facebook's AsyncDisplayKit to create a CollectionView such that CollectionView is ASCollectionView and i am trying to add UIKit's UIImageView in the cell.I get following crash:

  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ''

  *** First throw call stack:
  (

0   CoreFoundation                      0x00bf2946 __exceptionPreprocess + 182

1   libobjc.A.dylib                     0x0087ba97 objc_exception_throw + 44

2   CoreFoundation                      0x00bf27da +[NSException raise:format:arguments:] + 138

3   Foundation                          0x004ef810 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118

4   Sample                              0x000b21df -[ASDisplayNode view] + 607

5   Sample                              0x0007a0f5 -[PlainImageNode initWithCellOfSize:] + 533

6   Sample                              0x0007e34d -[ASVC_UIImage_ViewController collectionView:nodeForItemAtIndexPath:] + 269

7   Sample                              0x00085c36 -[ASCollectionView dataController:nodeAtIndexPath:] + 150


libc++abi.dylib: terminating with uncaught exception of type NSException

Following the code which crashes, this is the init method of the ASCellNode I created for my ASCollectionView. I am trying to add UIImageView into ASCellNode:

- (instancetype)initWithCellOfSize:(CGSize)size
{
if (!(self = [super init]))
    return nil;

_kittenSize = size;

// kitten image, with a solid background colour serving as placeholder
_imageView = [[UIImageView alloc] init];
_imageView.image = [UIImage imageNamed:@"testImage.jpg"];
_imageView.frame = CGRectMake(10.0f, 10.0f, 40.0f, 40.0f);
[self.view addSubview:_imageView];

[self setBackgroundColor:[UIColor yellowColor]];
return self;
}

I am afraid if I can add UIKit components to ASCollectionView's ASCellNode. Is it true that we can't add UIKit components in ASCellNode's hierarchy?

Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
Krati Jain
  • 368
  • 2
  • 10
  • There is nothing wrong with UIKit and AsyncDisplayKit. It must be your implementation, you need to see their sample more carefully. I guess you are trying to subclass `ASCellNode `, and doing some mistake there. – iphonic Mar 09 '15 at 06:42
  • I have gone through the sample projects provided along with the library. However, i couldn't find an example where they were adding a UIKit component to the ASCellNode hierarchy. It would really help if you can point to some working code of adding any UIKit component to ASCellNode. – Krati Jain Mar 09 '15 at 07:29
  • Similar issue with UIButton addition to ASCellNode : http://stackoverflow.com/questions/28831366/add-custom-button-with-asyncdisplaykit – Krati Jain Mar 09 '15 at 07:47
  • Did you see this http://asyncdisplaykit.org/guide/ ? Don't use UIImageView, use `ASImageNode` instead. And if you want to create Custom Node here it is http://asyncdisplaykit.org/guide/2/ – iphonic Mar 09 '15 at 07:52
  • I have gone through the complete guide. I am trying to create a small POC to check if we can add UIKit components to ASCellNode because there are some UIKit components whose wrapper nodes are not available in ASDisplayKit. Hence as part of POC, I took UIImageView to keep things simple. – Krati Jain Mar 09 '15 at 17:32

1 Answers1

0

Finally I was able to add UIKit components in the ASCellNode subclass implementation using -[ASDisplayNode initWithViewBlock:].

Following is the code which wraps an ASDisplayNode over UIImageView and returns the resulting node :

ASDisplayNode *_imageViewNode = [[ASDisplayNode alloc] initWithViewBlock:^{
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"testImage.jpg"]];
    return image;
}];
_imageViewNode.frame = CGRectMake(10.0f, 10.0f, 40.0f, 40.0f);
[self addSubnode:_imageViewNode];

Similarly, code for UIWebView component :

ASDisplayNode *webViewNode = [[ASDisplayNode alloc]initWithViewBlock:^{

NSString *strURL = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
UIWebView *webview = [[UIWebView alloc]init];
[webview loadRequest:urlRequest];
return webview;
}];

[webViewNode setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:webViewNode.view];
Krati Jain
  • 368
  • 2
  • 10