简体   繁体   English

在同一viewcontroller中调用Storyboard和Xib?

[英]call storyboard and xib in same viewcontroller?

I don't know how to load my page as it is, When i press back button. 我不知道如何按原样加载页面,当我按返回按钮时。 I have two type of pages storyboard and xib. 我有两种类型的页面情节提要和xib。 Which display all information, When i click go button it will taken to new page. 显示所有信息,当我单击“执行”按钮时,它将进入新页面。 All these working good, But my problem is when i press back button i need my storyboard and xib file should be display in same view. 所有这些工作都很好,但是我的问题是当我按下后退按钮时,我需要我的情节提要和xib文件应在同一视图中显示。 When i run my app it display only storyboard page xib didn't load. 当我运行我的应用程序时,它仅显示未加载的故事板页面xib。

Thanks for advance here's my code: 感谢您的前进,这是我的代码:

- (IBAction)back:(id)sender {
    Recharge *view = [self.storyboard instantiateViewControllerWithIdentifier:@"Recharge"];
    [self presentViewController:view animated:YES completion:nil];
    self.recharge = [[mobileViewcontroller alloc]init];
    self.recharge.view.frame = CGRectMake(0,100, 400, 400);
    [self addChildViewController:self.recharge];
    [self.view addSubview:self.recharge.view];
}

I'm assuming that Recharge is the view controller from the storyboard and mobileViewController is the view controller from the xib. 我假设Recharge是情节mobileViewController中的视图控制器,而mobileViewControllermobileViewController中的视图控制器。

You're calling the wrong constructor to load mobileViewController . 您正在调用错误的构造函数来加载mobileViewController You need to use (instancetype)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle to load it with a xib file. 您需要使用(instancetype)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle来加载xib文件。 See https://developer.apple.com/library/ios/Documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/initWithNibName:bundle : 参见https://developer.apple.com/library/ios/Documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/initWithNibName:bundle

Replace your code with 将您的代码替换为

- (IBAction)back:(id)sender {
    Recharge *rechargeView = [self.storyboard instantiateViewControllerWithIdentifier:@"Recharge"];
    [self presentViewController:rechargeView animated:YES completion:nil];

    self.recharge = [[mobileViewcontroller alloc]init];
    self.recharge.view.frame = CGRectMake(0,100, 400, 400);
    [rechargeView addChildViewController:self.recharge];
    [rechargeView.view addSubview:self.recharge.view];
}

And it will work. 它将起作用。

As you are adding your mobileViewcontroller view on your current viewController which is not visible to user, instead you should add your mobileViewcontroller to the the recharge viewController which is in hierarchy and visible to user. 当您在current viewController对用户不可见的mobileViewcontroller上添加mobileViewcontroller视图时,应将mobileViewcontroller添加到层次结构中且对用户可见的recharge viewController上。

when ever you call new viewcontroller with passing somthing you have do code like this put all code before[self presentViewController:view animated:YES completion:nil]; 每当您通过传递新东西来调用新的viewcontroller时,您都将这样的代码放在所有代码之前:[self presentViewController:view animation:YEScomplete:nil];

try this: 尝试这个:

  • (IBAction)back:(id)sender { (IBAction)后退:(id)发件人{

    Recharge *view = [self.storyboard instantiateViewControllerWithIdentifier:@"Recharge"]; 充值* view = [self.storyboard InstantiateViewControllerWithIdentifier:@“充值”];

    self.recharge = [[mobileViewcontroller alloc]init]; self.recharge = [[mobileViewcontroller alloc] init];

    self.recharge.view.frame = CGRectMake(0,100, 400, 400); self.recharge.view.frame = CGRectMake(0,100,400,400);

    [view addChildViewController:self.recharge]; [查看addChildViewController:self.recharge];

    [view addSubview:self.recharge.view]; [view addSubview:self.recharge.view];

    [self presentViewController:view animated:YES completion:nil]; [自己的presentViewController:动画视图:是完成:无];

    } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Storyboard和Xib用于同一ViewController? - use Storyboard and xib for same viewcontroller? 从ViewController(故事板)调用NavigationController(xib) - Call NavigationController (xib) from ViewController (storyboard) 从xib调用viewController - Call viewController from xib 使用相同的ViewController类从同一故事板调用第二个视图 - Call a second view from the same storyboard with the same ViewController class 我如何将 .xib ViewController 转到 Storyboard ViewController 并再次将 Storyboard 转到 .xib ViewController - How can i go .xib ViewController to storyboard ViewController and again storyboard to .xib ViewController 如何从 xib 到 storyboard 的视图控制器? - How to segue from a xib to a viewcontroller from a storyboard? 能够从Storyboard和ViewController加载xib - Be able to load xib from both Storyboard and ViewController 如何在同一ViewController(在情节提要板上创建)的两个视图(在xib中创建)之间切换? - How can I switch between two view (created on xib) over the same ViewController (created on storyboard)? 无法从xib调用storyboard - Unable to call storyboard from xib 从Storyboard ViewController返回到以前使用的.xib ViewController - Going back from Storyboard ViewController to a previously used .xib ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM