I’m trying to migrate some of my view controllers and UITableView
subclasses over to using Typhoon, but I can’t find any documentation around what to do with cells that are generated from a tableView’s dequeReusableCellWithIdentifier
.
The TableViewController I’m working with uses multiple cell types which it registers with the TableView in viewDidLoad
using registerNib:forCellReuseIdentifer:
.
What should we do to have Typhoon inject cells loaded from xibs?
Probably the easiest thing to do would be to create a view assembly for your xib loaded table cells, and make this one of your application assemblies. Assuming you're using plist integration then you'd add it to your app's plist as:
<key>TyphoonInitialAssemblies</key>
<array>
<string>ViewProvider</string>
<string>ApplicationAssembly</string>
<string>CoreComponentsAssembly</string>
<string>NetworkAssembly</string>
</array>
Logically it would sit to the side of your top-level application assembly.
@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;
Next inject this into your 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;
}
The documentation for this feature is here.