enhance controller registration to allow for configuration

This commit is contained in:
Kyle Matthew Hedden 2020-10-30 14:10:14 -04:00
parent 11d7fcb4d7
commit 147a237ba9
2 changed files with 17 additions and 1 deletions

View File

@ -13,7 +13,11 @@
// View Controller Class, for loading by class.
@property (nonnull, strong, nonatomic) Class viewControllerClass;
@property (nullable, copy, nonatomic) void (^configureHandler)(UIViewController * _Nonnull);
// Initializes with the given class.
- (nullable id)initWithClass:(nonnull Class)viewControllerClass;
- (nullable id)initWithClass:(nonnull Class)viewControllerClass configureHandler:(void(^_Nonnull)(UIViewController * _Nonnull))configureBlock;
@end

View File

@ -19,8 +19,20 @@
return self;
}
- (nullable id)initWithClass:(nonnull Class)viewControllerClass configureHandler:(void(^)(UIViewController * _Nonnull))configureBlock {
self = [self initWithClass:viewControllerClass];
if (self) {
self.configureHandler = configureBlock;
}
return self;
}
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createViewController {
return [[self.viewControllerClass alloc] init];
UIViewController <MVMCoreViewControllerProtocol> *newController = [[self.viewControllerClass alloc] init];
if (self.configureHandler) {
self.configureHandler(newController);
}
return newController;
}
@end