台风注入xib装载的表格细胞

时间:2015-02-20 01:33:00

标签: ios objective-c uikit typhoon

我正在尝试将一些视图控制器和UITableView子类迁移到使用Typhoon,但我找不到任何关于如何处理从tableView {{1}生成的单元格的文档}。

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

我们应该怎样做才能让台风注射细胞从xibs加载?

1 个答案:

答案 0 :(得分:3)

最简单的方法可能是为xib加载的表格单元创建一个视图程序集,并将其作为一个应用程序集。假设您正在使用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;

接下来将其注入视图控制器。

@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

相关问题