致命错误:在加载UITableView时展开Optional值时意外发现nil

时间:2017-10-12 07:15:35

标签: swift xcode uitableview

我在旁边菜单中使用这个类: https://github.com/evnaz/ENSwiftSideMenu 我已将侧边菜单ViewController创建为UITableViewController并且工作正常,现在我刚刚创建了SideMenuViewController,如下所示:

class SideMenuViewController: UIViewController , UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var SideTableView: UITableView!



    override func viewDidLoad() {
        super.viewDidLoad()

        SideTableView.frame = CGRect(x:0 , y:20 , width :screenWidth , height: screenHeight)

          }


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print ("rows function")
        return 10
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        print ("sections function")

        return 1
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        print ("cell function")

        let cellIdentifier = "Cellid"
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
        cell.textLabel?.text = "Hello"
        return cell
    }

}

然后我用UITableView替换了SideMenuViewController,但每次运行时都会出现以下错误:

  

致命错误:在展开Optional值时意外发现nil   (LLDB)

这是NavigationController

class NavigationController: ENSideMenuNavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()
        sideMenu = ENSideMenu(sourceView: self.view,menuViewController: SideMenuViewController(), menuPosition:.left)
        sideMenu?.menuWidth = 200
        view.bringSubview(toFront: navigationBar)

    }

}

这是错误:

enter image description here

注意:当我单独运行SideMenuViewController时,它工作正常,就像嵌入作为侧边菜单时我得到了错误。

0 个答案:

没有答案