如何在Swift 3中配置幻灯片菜单中的菜单选项?

时间:2017-06-21 17:38:24

标签: swift uitableview swift3 menu

我已成功设置幻灯片菜单,但无法显示菜单选项。菜单是空的。

我搜索过高低。我无法找到答案。我一直在看我的代码好几天(当然)它看起来对我来说。

class LeftTableViewController: UITableViewController {

@IBOutlet var menuTableView: UITableView!

let menuItems = ["First", "Second", "Third", "Fourth"]

override func viewDidLoad() {
    super.viewDidLoad()

    navigationController?.setNavigationBarHidden(true, animated: true)

    if (tableView(tableView: self.tableView, numberOfRowsInSection: 1) == 0 ) {
        let emptyStateLabel = UILabel(frame: tableView.frame)
        emptyStateLabel.text = "At this time, nothing is here."

        tableView.backgroundView = emptyStateLabel
    } else {
        tableView.backgroundView = nil

    }

}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Added a background view to the table view
    let backgroundImage = UIImage(named: "growlTaps.png")
    let imageView = UIImageView(image: backgroundImage)
    self.tableView.backgroundView = imageView

    // Remove lines where there aren't cells
    tableView.tableFooterView = UIView(frame: CGRect.zero)

    // Center and scale background image
    imageView.contentMode = .scaleAspectFit

    // Center and scale background image
    imageView.contentMode = .scaleAspectFill

    // Set the background color
    tableView.backgroundColor = .lightGray
}

// MARK: - Table view data source
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return menuItems.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "LeftTableViewControllerCellIdentifier")!
    cell.textLabel?.text = menuItems[indexPath.row]
    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
    switch indexPath.row {
    case 0:
        self.sideMenuViewController!.setContentViewController(contentViewController: UINavigationController.init(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "ViewController")), animated: true)
        self.sideMenuViewController!.hideMenuViewController()
        break
    case 1:
        self.sideMenuViewController!.setContentViewController(contentViewController:UINavigationController.init(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "AboutViewController")), animated: true)
        self.sideMenuViewController!.hideMenuViewController()
        break
    case 2:
        self.sideMenuViewController!.setContentViewController(contentViewController:UINavigationController.init(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "ContactVC")), animated: true)
        self.sideMenuViewController!.hideMenuViewController()
        break
    default:
        break
    }
}
}

编辑:桌面视图的插座。 enter image description here enter image description here

0 个答案:

没有答案