Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用共享故事板设计加载正确的UIViewController?_Ios_Xcode_Uiviewcontroller_Subclass_Uistoryboard - Fatal编程技术网

Ios 如何使用共享故事板设计加载正确的UIViewController?

Ios 如何使用共享故事板设计加载正确的UIViewController?,ios,xcode,uiviewcontroller,subclass,uistoryboard,Ios,Xcode,Uiviewcontroller,Subclass,Uistoryboard,我在一个故事板中设计了一个屏幕,它由几个控制器子类化。它们的设计都是一样的 现在,我需要加载屏幕。据我所知,我确实: 但是,这将加载基类,而不是子类。(基类是SearchViewController,子类是SearchCustomServiceController)。我能做什么 这就是基类和子类的代码: @interface SearchViewController : UIViewController <SqliteDataSource> - (IBAction)show

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

现在,我需要加载屏幕。据我所知,我确实:

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

这就是基类和子类的代码:

@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;
}
@界面SearchViewController:UIViewController
-(iAction)显示菜单:(id)发送者;
-(iAction)addNew:(id)发送方;
-(id)initWithRouterParams:(NSDictionary*)参数;
@属性(强,非原子)NSDictionary*参数;
@属性(弱、非原子)IBOutlet搜索栏*editSearch;
@属性(弱、非原子)IBUITableView*搜索结果;
@性质(弱、非原子)IbUitoolbar*barActions;
+(id)加载:(类)名称;
@结束
@实现SearchViewController
+(id)allocWithRouterParams:(NSDictionary*)参数{
UIStoryboard*b=[UIStoryboard情节提要,名称:@“MainstryBoard”捆绑包:nil];
SearchViewController*c=[b实例化视图控制器的标识符:@“SearchViewController”];
返回c;
}
-(无效)viewDidLoad
{
[超级视图下载];
self.editSearch.hideTable=否;
[self.editSearch成为第一响应者];
}
+(id)加载:(类)名称{
return[name allocWithRouterParams:nil];
}
@界面CustomerListViewController:SearchViewController
@属性(弱、非原子)CustomerModel*customerData;
@结束
-(无效)viewDidLoad{
[超级视图下载];
self.customerData=[CustomerModel setupController:self-searchResult:self.searchResults-searchCustomer:self.editSearch-hideTable:NO onSelectModel:^(NSMutableDictionary*数据){
NSInteger theId=[data[@“id”]integerValue];
[self-setCustomer:[Db currentDb]loadById:[Customer class]theId:theId];
}];
self.customerData.filter=CUSTOMER\u filter\u NONE;
}

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


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

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


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

为子类提供一个标识符,然后尝试以与以前相同的方式实例化视图控制器。你也试过上面的代码了吗?它可能会做你想要它做的事情。复制屏幕需要一个不同的标识符,这是我希望避免的。所以你不需要不同的标识符或者不想复制屏幕…我不能说我不想复制屏幕。多个继承UIViewControllers的同一屏幕不会复制该屏幕。只需代替
[b instantialeviewcontrollerwhiteIdentifier:@“SearchViewController”]执行<代码>[b实例化eViewController标识符:@“SearchCustomServiceController”]在给故事板中的子类一个标识符之后。给你的子类一个标识符,然后尝试用与之前相同的方法实例化视图控制器。你也试过上面的代码了吗?它可能会做你想要它做的事情。复制屏幕需要一个不同的标识符,这是我希望避免的。所以你不需要不同的标识符或者不想复制屏幕…我不能说我不想复制屏幕。多个继承UIViewControllers的同一屏幕不会复制该屏幕。只需代替
[b instantialeviewcontrollerwhiteIdentifier:@“SearchViewController”]执行<代码>[b实例化eViewController标识符:@“SearchCustomServiceController”]在你给故事板中的子类一个标识符之后。那么,从xib加载它的唯一选项是什么呢?是的,不过我会看看你是如何设计你的子类的。使用类别或类似的东西可能更有意义。那么,从xib加载它的唯一选项是什么呢?是的,不过我想看看您是如何设计子类的。使用类别或类似的东西可能更有意义。
@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;
}