[英]Cannot assign value of type 'Class<T>' to type 'protocol<UIImagePickerControllerDelegate, UINavigationControllerDelegate>?'
[英]Cannot assign value of type 'Class' to type '[Class]'
我正在設置我的第一個Swift項目,並且當前出現此錯誤:
Cannot assign value of type 'UIViewController' to type '[UIViewController]'
我暗中懷疑這與這一切有關?
!
商業...
我以為我有?
找出並充分理解了!
入門,但是當我開始研究應用程序委托初始化時,我對他們使用!
的方式感到困惑!
秒。 到目前為止,這是我在didFinishLaunchingWithOptions
方法中得到的:
self.window = UIWindow(frame: UIScreen.mainScreen().bounds);
self.navCtrlr = UINavigationController();
self.rootVC = RootViewController(nibName: nil, bundle: nil);
self.navCtrlr!.viewControllers = self.rootVC! as UIViewController; ****
self.window!.rootViewController = self.rootVC;
self.window?.makeKeyAndVisible();
第4行(帶****)是有問題的那一行。 最初,我使用self.rootVC as UIViewController
而不使用!
,但出現錯誤,要求我添加!
, 所以我做了。 現在,我得到了我現在遇到的錯誤。 這是我的類屬性的樣子:
var window: UIWindow?;
var navCtrlr = UINavigationController?();
var rootVC: RootViewController?;
老實說,UINavigationController實例化也使我感到困惑...我們使用?
的原因?
是因為我們希望變量能夠包含nil,而不必在創建對象之前對其進行定義,對嗎? 那么,為什么在()
結尾呢? 但是我離題了。
'UIViewController'
和'[UIViewController]'
之間有什么區別,我該怎么辦才能使此錯誤消失?
嘗試
self.navCtrlr!.viewControllers = [self.rootVC! as UIViewController];
[UIViewController]
是快速數組
此外,我認為rootViewController
是navigationController,所以
self.window = UIWindow(frame: UIScreen.mainScreen().bounds);
self.rootVC = RootViewController(nibName: "youNibName", bundle: nil);
self.navCtrlr = UINavigationController(rootViewController: self.rootVC!);
self.window!.rootViewController = self.navCtrlr;
self.window?.makeKeyAndVisible();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.