在Swift中将View控制器添加为子视图 [英] Adding View controllers as subview in Swift
问题描述
我正在尝试使用swift构建一个简单的计算器应用。我用基本和高级选项创建了两个视图控制器。以前在Obj-C中曾经这样做过
Am trying to build a simple calculator app using swift. I have created two view controller with the basic and advanced options. Earlier in Obj-C used to do this
[[AViewController alloc] initWithNibName:@"nibName" bundle:nil]
很快,我什至无法导入新的视图控制器。但是我仍然可以声明为 var aViewController:AViewController?
并使用它。但是我被困在加载笔尖
In swift I cannot even import my new view controllers. But still I can declare as var aViewController:AViewController?
and use it. But I am stuck at loading nib
我尝试了 AViewController(nibName: nibname,bundle:nil)
,但一切都会导致编译器错误找不到接受提供的参数的__conversion的重载
I tried with AViewController(nibName: "nibname", bundle: nil)
, but everything results in compiler error Could not find an overload for __conversion that accepts the supplied arguments
推荐答案
像 nil
一样,当我用 NSBundle.mainBundle()
可行。
这篇关于在Swift中将View控制器添加为子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!