[英]How to replace storyboard with an '.xib' file in coding
I found a UIPagecontrol example while googling and this works perfectly when i try to create this as a completely new project. 我在谷歌搜索时发现了一个UIPagecontrol示例,当我尝试将其创建为一个全新的项目时,它可以完美地工作。 Now i want to add this to my code
现在我想将此添加到我的代码中
@interface filename2 ()
@end
@implementation filename2
@synthesize View1;
@synthesize View2;
@synthesize View3;
- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View1"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View2"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View3"]];
}
@end
But the problem I'm facing is that I'm not using storyboard I'm using ViewController.xib so how can i change this code to use it with my application? 但是我面临的问题是我没有使用情节提要,而是使用ViewController.xib,所以如何更改此代码以将其与我的应用程序一起使用?
Use initWithNibName : Method for using xibs. 使用initWithNibName :使用xibs的方法。
Example 例
ViewController *v1=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self addChildViewController: v1]];
用您的ViewController
对象替换[self.storyboard instantiateViewControllerWithIdentifier:@"View1"]
。
Have you tried using 您是否尝试过使用
NSArray* views = [[NSBundle mainBundle] loadNibNamed: owner: options:] NSArray *视图= [[[NSBundle mainBundle] loadNibNamed:所有者:选项:]
Xib is a Nib in xml format. Xib是xml格式的Nib。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.