我正在尝试将我的一些 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/