我有一个 Base Class
我继承了我的Parent Class
从此Base Class
.
现在我有另一个 ViewController
与 XIB
.我只想展示这个XIB as
我的父类中的 View 。
我的姓名ViewController
与 XIB 为: SearchResultDisplayVC
我正在使用我的基类将我的 XIB 显示为 View 的这段代码:
- (void)showSearchResultsView
{
SearchResultDisplayVC *searchView =(SearchResultDisplayVC *)[[[NSBundle mainBundle] loadNibNamed:@"SearchResultDisplayVC" owner:[SearchResultDisplayVC class] options:nil] firstObject];
[self.view addSubview:searchView.view];
}
在我的父类中,我将其称为“
[self showSearchResultsView];
虽然我在编译时没有收到任何错误消息,但是当我运行我的应用程序时它崩溃并显示以下消息:
*** Terminating app due to uncaught exception
'NSUnknownKeyException',
reason: '[<SearchResultDisplayVC 0x1104bb380> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
最佳答案
您必须在父 View 中添加为 subview Controller 。
SearchResultDisplayVC * searchView = [[SearchResultDisplayVC alloc] initWithNibName:@"SearchResultDisplayVC" bundle:nil];
self.addChildViewController(searchView)
关于ios - 如何在另一个 ViewController 中将带有 Xib 的 ViewController 显示为 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34692182/