ios - 如何在编码中用 '.xib' 文件替换 Storyboard

标签 ios iphone objective-c xcode-storyboard

我在谷歌搜索时发现了一个 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

但我面临的问题是我没有使用 Storyboard 我使用的是 ViewController.xib 那么如何更改此代码以将其用于我的应用程序?

最佳答案

使用initWithNibName:使用xibs的方法。

例子

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

关于ios - 如何在编码中用 '.xib' 文件替换 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22317318/

相关文章:

objective-c - 为 iOS 应用设置样式的推荐方法是什么?

ios - 找到一周中依赖于语言环境的第一天

iphone - 一个接一个地执行方法,执行之间有暂停

ios - 如何预览在 .xib 文件中以编程方式创建的项目?

iphone - 是否可以在 Objective-C 中重定向系统 API?

iphone - For 循环 Objective-C

ios - 如何为一个 Controller 设置多个 View

ios - 在 iOS 中播放准备好的动画

iphone - MKStoreKit -isSubscriptionActive 总是返回 False

objective-c - 在 Objective-C 中打印多个页面