gpt4 book ai didi

ios - 如何使用共享 Storyboard设计加载正确的 UIViewController?

转载 作者:行者123 更新时间:2023-11-29 13:10:23 24 4
gpt4 key购买 nike

我在 Storyboard中设计了一个屏幕,该屏幕由多个 Controller 子类化。它们的设计都是相同的。

现在,我需要加载屏幕。根据How can I load storyboard programmatically from class? ,我这样做:

UIStoryboard *b = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SearchViewController *c = [b instantiateViewControllerWithIdentifier:@"SearchViewController"];

return c;

但是,这会加载基类,而不是子类。 (基类是 SearchViewController,子类是 SearchCustomerViewController)。我能做什么?

P.D:基类和子类的代码是这样的:

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

最佳答案

Storyboard View Controller 将始终使用您在 Storyboard中选择的类进行实例化。您不能只导入“ View ”并拥有自定义 Controller 。

您要么需要复制您的设计,要么需要重构您构建 View Controller 的方式。一种选择是嵌入式 View Controller 。

关于ios - 如何使用共享 Storyboard设计加载正确的 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17554385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com