nie*_*els 14 iphone cocoa-touch xib uiviewcontroller nib
我将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类.是的,我记得以后再将它连接到视图插座.
请帮忙!我很难过.
drv*_*ijk 16
你有没有重写PageViewController中的loadView方法?如果您对viewController1.view进行NSLog,该怎么办?
实际上,在Interface Builder中,您必须将文件的所有者设置为PageViewController,并将其视图连接到Interface Builder中的视图.
| 归档时间: |
|
| 查看次数: |
41442 次 |
| 最近记录: |