ios - 台风注入(inject) xib 加载表单元格

标签 ios objective-c uikit typhoon

我正在尝试将我的一些 View Controller 和 UITableView 子类迁移到使用 Typhoon,但我找不到任何关于如何处理从 tableView 生成的单元格的文档 dequeReusableCellWithIdentifier

我正在使用的 TableViewController 使用多个单元格类型,它使用 registerNib:forCellReuseIdentifer:viewDidLoad 中向 TableView 注册。

我们应该怎么做才能让 Typhoon 注入(inject)从 xibs 加载的细胞?

最佳答案

可能最简单的事情是为您的 xib 加载表单元格创建一个 View 程序集,并将其作为您的应用程序程序集之一。假设您使用的是 plist integration然后你将它添加到你的应用程序的 plist 中:

<key>TyphoonInitialAssemblies</key>
<array>
    <string>ViewProvider</string>
    <string>ApplicationAssembly</string>
    <string>CoreComponentsAssembly</string>
    <string>NetworkAssembly</string>
</array>

从逻辑上讲,它将位于顶级应用程序程序集的一侧。

@interface ViewProvider : TyphoonAssembly

//Reference any other assemblies that you need
@property(nonatomic, strong, readonly) CoreComponents *coreComponents;

//Create a definition for the table cell with the injections that need to happen. 
- (UITableViewCell*)myTableViewCell;

接下来将其注入(inject)到您的 View Controller 中。

@interface MyViewController : UIViewController

@property (nonatomic, strong) InjectedClass(ViewAssembly) viewProvider;

@end 

@implementation MyViewController

- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //Load the cell from the XIB first. 
    //And now tell Typhoon to inject it
    [self.viewProvider inject:cell];
    //The above matches by type, you can also provide an @selector() 
    //definition in the assembly

    //Any other config to the cell
    return cell;

}

此功能的文档是 here .

关于ios - 台风注入(inject) xib 加载表单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28620255/

相关文章:

ios - 为什么阴影反射(reflect)在 subview 上

ios - UIMotionEffect 的视差效果不起作用

ios - 使用 UIPageViewController 在多个 View Controller 之间滑动

iphone - Objective C - 在 UITextView 中显示数据

objective-c - 从任何地方以编程方式在 iOS 上截取屏幕截图

iphone - 无法获取图片的 [ALAsset 缩略图],但适用于视频

iphone - 突出显示的阴影颜色

ios - 在 ARC 下处理容器中 CGImageRef 的正确方法

ios - ResourceManager.write Data(for...不会在 iOS 14 上运行

ios - 检测 UITableView 下面的 UIPageView 上的滑动事件