当前位置 : 主页 > 手机开发 > 其它 >

swift – 类型UIViewController的值在Xcode 7更新后没有成员topViewController

来源:互联网 收集:自由互联 发布时间:2021-06-11
在我更新到 Xcode 7后,我收到此错误“类型UIViewController的值没有成员topViewController.”其他人遇到这个? topViewController不再是UIViewController的一部分吗? override func viewDidLoad() { super.viewDidLo
在我更新到 Xcode 7后,我收到此错误“类型UIViewController的值没有成员topViewController.”其他人遇到这个? topViewController不再是UIViewController的一部分吗?

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.leftBarButtonItem = self.editButtonItem()
    let addButton = UIBarButtonItem(barButtonSystemItem: .Search,
        target: self, action: "addButtonPressed:")
    self.navigationItem.rightBarButtonItem = addButton

    if let split = self.splitViewController {
        let controllers = split.viewControllers
        self.detailViewController =
            controllers[controllers.count-1].topViewController as? ### Error heres
        DetailViewController
    }

    model = Model(delegate: self) // create the Model
    model.synchronize() // tell model to sync its data
    self.navigationController?.toolbarHidden = false;
    self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"Home", style:.Plain, target:nil, action:nil)
}
你必须明确它,以便它知道你正在尝试从Swift 2中的UINavigationController获取topViewController:

self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController
网友评论