我使用Facebook的AsyncDisplayKit
创建CollectionView
,CollectionView
为ASCollectionView
,我正在尝试添加UIKit's
UIImageView
细胞。我得到了以下的崩溃:
*** 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
在崩溃的代码之后,这是我为ASCellNode
创建的ASCollectionView
的init方法。我正在尝试将UIImageView
添加到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;
}
我担心如果我可以将UIKit
组件添加到ASCollectionView's
ASCellNode
。是的,我们无法在UIKit
层次结构中添加ASCellNode's
个组件吗?
答案 0 :(得分:0)
最后,我能够使用 - [ASDisplayNode initWithViewBlock:]在ASCellNode子类实现中添加UIKit组件。
以下是通过UIImageView包装ASDisplayNode并返回结果节点的代码:
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];
类似地,UIWebView组件的代码:
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];