我将UIViewController子类化为一个新类,PageViewController(我正在编写一个简单的书籍应用程序).我想添加从nib文件加载的新视图,并使用以下代码.有用.
PageViewController *viewController1 = [[UIViewController alloc] initWithNibName:@"Page1" bundle:nil];
[viewController1.view setUserInteractionEnabled:YES];
[self.view addSubview:viewController1.view];
Run Code Online (Sandbox Code Playgroud)
但是,第一行是错误的,因为我应该在PageViewController上调用alloc.当我更正它(下面)时,代码编译但xib文件没有加载,视图只是透明的.
PageViewController *viewController1 = [[PageViewController alloc] initWithNibName:@"Page1" bundle:nil];
[viewController1.view setUserInteractionEnabled:YES];
[self.view addSubview:viewController1.view];
Run Code Online (Sandbox Code Playgroud)
PageViewController initWithNibName方法已取消注释,只是默认设置,设置为self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil].
我尝试过:在Page1 nib文件中,我尝试在PageViewController和UIViewController之间更改File Owner类.是的,我记得以后再将它连接到视图插座.
请帮忙!我很难过.