可能最简单的做法是为加载 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;
}
此功能的文档在此处。