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