我在故事板中设计了一个屏幕,该屏幕由多个控制器子类化。他们的设计都是一样的。
现在,我需要加载屏幕。根据如何从课堂上以编程方式加载情节提要?, 我愿意:
UIStoryboard *b = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SearchViewController *c = [b instantiateViewControllerWithIdentifier:@"SearchViewController"];
return c;
但是,这会加载基类,而不是子类。(基类是 SearchViewController,子类是 SearchCustomerViewController)。我可以做什么?
PD:基类和子类的代码是这样的:
@interface SearchViewController : UIViewController
<SqliteDataSource>
- (IBAction)showMenu:(id)sender;
- (IBAction)addNew:(id)sender;
- (id)initWithRouterParams:(NSDictionary *)params;
@property (strong, nonatomic) NSDictionary *params;
@property (weak, nonatomic) IBOutlet SearchBar *editSearch;
@property (weak, nonatomic) IBOutlet UITableView *searchResults;
@property (weak, nonatomic) IBOutlet UIToolbar *barActions;
+ (id)load:(Class)name;
@end
@implementation SearchViewController
+ (id)allocWithRouterParams:(NSDictionary *)params {
UIStoryboard *b = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SearchViewController *c = [b instantiateViewControllerWithIdentifier:@"SearchViewController"];
return c;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.editSearch.hideTable = NO;
[self.editSearch becomeFirstResponder];
}
+ (id)load:(Class)name {
return [name allocWithRouterParams:nil];
}
@interface CustomerListViewController : SearchViewController
@property (weak, nonatomic) CustomerModel *customerData;
@end
-(void) viewDidLoad {
[super viewDidLoad];
self.customerData = [CustomerModel setupController:self searchResult:self.searchResults searchCustomer:self.editSearch hideTable:NO onSelectModel:^(NSMutableDictionary *data) {
NSInteger theId = [data[@"id"] integerValue];
[self setCustomer:[[Db currentDb] loadById:[Customer class] theId:theId]];
}];
self.customerData.filter = CUSTOMER_FILTER_NONE;
}