【问题标题】:ComponentKit how push view controllers CKComponentControllerComponentKit 如何推送视图控制器 CKComponentController
【发布时间】:2015-07-27 08:53:56
【问题描述】:

您好,刚刚声明要使用 facebook 提供的 ComponentKit 库 我一直在浏览他们的所有文档,但我找不到如何使用他们的 CKComponentController 类。

比如如何推送一个视图控制器以及各种视图控制器的导航。

如果有人知道如何使用CKComponentController,请告诉我 由于文档较少,我有点卡住了

谢谢。 伊姆兰。

【问题讨论】:

    标签: ios objective-c viewcontroller componentkit


    【解决方案1】:

    我们通常的做法是将带有弱引用的对象作为“上下文”对象传递给导航控制器,然后传递给顶级组件。

    确保它是一个弱引用,否则你会得到一个保留循环!

    至于在组件控制器中访问它,将上下文对象公开为组件上的属性,然后从self.component 中读取该属性。

    【讨论】:

    • 嘿,感谢您的回答,但我有一些疑问。 prepareForSugue、performSegueWithIdentifier 等呢?
    【解决方案2】:

    我解决了这个问题,但它绝对不是立即显而易见的。我不得不挖掘源代码。 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");
    
    }
    
    @end
    

    【讨论】:

      猜你喜欢
      • 2010-12-11
      • 1970-01-01
      • 2023-04-09
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      相关资源
      最近更新 更多