1

我在故事板中设计了一个屏幕,该屏幕由多个控制器子类化。他们的设计都是一样的。

现在,我需要加载屏幕。根据如何从课堂上以编程方式加载情节提要?, 我愿意:

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;
}
4

1 回答 1

1

情节提要视图控制器将始终使用您在情节提要中选择的类进行实例化。您不能只导入“视图”并拥有自定义控制器。

你要么需要复制你的设计,要么重构你构建视图控制器的方式。一种选择是嵌入式视图控制器。

于 2013-07-09T17:49:09.073 回答