2014-06-17 95 views
2

我正試圖用swift構建一個簡單的計算器應用程序。我用基本和高級選項創建了兩個視圖控制器。早先在Obj-C用來做這件事在Swift中添加視圖控制器作爲子視圖

[[AViewController alloc] initWithNibName:@"nibName" bundle:nil] 

在swift中我甚至無法導入我的新視圖控制器。但我仍然可以申報爲var aViewController:AViewController?並使用它。但我卡在裝載筆尖

我試圖與AViewController(nibName: "nibname", bundle: nil),但一切都導致編譯器錯誤Could not find an overload for __conversion that accepts the supplied arguments

回答

2

貌似nil是當我與NSBundle.mainBundle()取代了它,它的工作的一個作祟。

3

試試這個,

AViewController(nibName: "nibname", bundle: NSBundle.mainBundle()) 

這工作非常適合我。

宣言:SWIFTUINib類參考)

init(nibName name: String!, 
     bundle bundleOrNil: NSBundle!) -> UINib 

宣言:SWIFT的UIViewController類參考)

init(nibName nibName: String!, 
     bundle nibBundle: NSBundle!) 

感嘆號有效說,「我知道這個可選項肯定有價值;請使用它。「這就是所謂的強制展開選項的值

就是這個原因,我們無法通過「零」作爲第二個參數即束

乾杯..!

相關問題