嗨,我刚刚声明要使用facebook提供的ComponentKit库,我已经浏览了他们的所有文档,但我找不到如何使用他们的CKComponentController类。
比如如何推送视图控制器以及各种视图控制器的导航。
如果你们中的任何人知道如何使用CKComponentController,请让我知道我有点卡住了,因为文档较少
谢谢。伊姆兰。
发布于 2015-05-15 23:54:50
我们通常的方法是将带有弱引用的对象作为“上下文”对象传递给导航控制器,该对象被传递给顶级组件。
确保它是一个弱引用,否则你将以保留循环结束!
至于在组件控制器中访问它,将context对象公开为组件上的属性,然后从self.component中读取该属性。
发布于 2015-05-27 21:22:41
我解决了这个问题,但肯定不是一目了然。我不得不翻遍源代码。StoryViewController扩展了UIViewController。
@interface StoryViewController () <
CKComponentProvider,
CKComponentHostingViewDelegate
>
@end
@implementation StoryViewController {
CKComponentDataSource *_componentDataSource;
CKComponentFlexibleSizeRangeProvider *_sizeRangeProvider;
}
- (void)viewDidLoad {
_sizeRangeProvider = [CKComponentFlexibleSizeRangeProvider providerWithFlexibility:CKComponentSizeRangeFlexibleHeight];
CKComponentHostingView *hostingView = [[CKComponentHostingView alloc] initWithComponentProvider:[self class]
sizeRangeProvider:_sizeRangeProvider
context:nil];
hostingView.delegate = self;
hostingView.model = self.story;
CGSize size = [hostingView sizeThatFits:CGSizeMake(self.view.frame.size.width, FLT_MAX)];
hostingView.frame = CGRectMake(0, 0, size.width, size.height);
[self.view addSubview:hostingView];
}
#pragma mark - CKComponentProvider
+ (CKComponent *)componentForModel:(id<NSObject>)story context:(id<NSObject>)context {
return [StoryComponent newWithStory:story context:nil];
}
#pragma mark - CKComponentHostingViewDelegate <NSObject>
- (void)componentHostingViewDidInvalidateSize:(CKComponentHostingView *)hostingView {
NSLog(@"componentHostingViewDidInvalidateSize");
}
@endhttps://stackoverflow.com/questions/30259378
复制相似问题