[英]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
中的视图控制器,而mobileViewController
是mobileViewController
中的视图控制器。
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.