Ios 无法分配类型为';UIViewController';输入';左视图控制器';。为什么?
我有一个类Ios 无法分配类型为';UIViewController';输入';左视图控制器';。为什么?,ios,swift,Ios,Swift,我有一个类LeftViewController: protocol LeftMenuProtocol: class { func actionOpenHome() func actionOpenTakeSnap() func actionOpenGallery() func actionOpenProfiles() func actionOpenSettings() func actionOpenHelp() func actionOpenContactUs() func actionOpenB
LeftViewController
:
protocol LeftMenuProtocol: class {
func actionOpenHome()
func actionOpenTakeSnap()
func actionOpenGallery()
func actionOpenProfiles()
func actionOpenSettings()
func actionOpenHelp()
func actionOpenContactUs()
func actionOpenBarCode()
func actionOpenAbout()
func actionCloseSideVC()
}
class LeftViewController : UIViewController {
@IBOutlet weak var tableView: UITableView!
var leftMenuDelegate : LeftMenuProtocol?
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.view.layoutIfNeeded()
}
}
我正在尝试将它添加到另一个类似这样的类中
var leftViewController: LeftViewController!
leftViewController = self.storyboard!.instantiateViewControllerWithIdentifier("LeftViewController")
self.addChildViewController(leftViewController)
self.view!.addSubview(leftViewController.view!)
leftViewController.didMoveToParentViewController(self)`
但是得到这个错误。有人知道怎么回事吗?将变量声明更改为
leftViewController = self.storyboard!.instantiateViewControllerWithIdentifier("LeftViewController") as! LeftViewController
您需要显式强制转换它。将变量声明更改为
leftViewController = self.storyboard!.instantiateViewControllerWithIdentifier("LeftViewController") as! LeftViewController
您需要显式强制转换它。或者他甚至可以将控制器视为
UIViewController
,因为在这部分代码中没有使用LeftViewController
一致性。或者他甚至可以将控制器视为UIViewController
一致性,因为在这部分代码中,LeftViewController
不一致性用过。