![](/img/trans.png)
[英]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.