0

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

我正在使用的 TableViewController 使用多种单元格类型,这些单元格类型在viewDidLoadusing中向 TableView 注册registerNib:forCellReuseIdentifer:

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

4

1 回答 1

3

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

}

此功能的文档在此处

于 2015-02-20T02:15:29.217 回答