1

我正在使用 FacebookAsyncDisplayKit创建一个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. 我正在尝试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

4

1 回答 1

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];
于 2015-03-09T20:18:57.503 回答