如何在编码中用'.xib'文件替换故事板

时间:2014-03-11 05:41:37

标签: ios iphone objective-c xcode-storyboard

我在google搜索时发现了一个UIPagecontrol示例,当我尝试将其创建为一个全新的项目时,这非常有效。现在我想将其添加到我的代码中

@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

但是我面临的问题是我没有使用故事板我正在使用ViewController.xib所以如何更改此代码以将其与我的应用程序一起使用?

3 个答案:

答案 0 :(得分:2)

使用 initWithNibName :使用xibs的方法。

实施例

ViewController *v1=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self addChildViewController: v1]];

答案 1 :(得分:1)

[self.storyboard instantiateViewControllerWithIdentifier:@"View1"]替换为ViewController的对象。

答案 2 :(得分:0)

您是否尝试过使用

NSArray * views = [[NSBundle mainBundle] loadNibNamed:owner:options:]

Xib是xml格式的Nib。

相关问题