类型'SideBar'不符合协议'SideBarTableViewControllerDelegate'

时间:2016-05-10 19:42:44

标签: ios xcode swift

我正在编写侧边栏,我收到了此错误

import UIKit


@objc protocol SideBarDelegate{
    func sideBarDidSelectButtonAtIndex(index:Int)
    optional func sideBarWillClose()
    optional func sideBarWillOpen()
}

class SideBar: NSObject, SideBarTableViewControllerDelegate {

    let barWidth:CGFloat = 150.0
    let sideBarTableViewTopInsert:CGFloat = 64.0
    let sidebarContainerView:UIView = UIView()
    let sideBarTableViewController:SideBarTableViewController = SideBarTableViewController()
    var originView:UIView! = nil

    var animator:UIDynamicAnimator!
    var delegate:SideBarDelegate?
    var isSideBarOpen:Bool = false

    override init() {
        super.init()
    }

    init(sourceView:UIView, menuItems:Array<String>)
    {
      super.init()
        originView = sourceView
        sideBarTableViewController.tableData = menuItems

        setupSideBar()

        animator = UIDynamicAnimator(referenceView: originView)

        let showGestureRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
        showGestureRecognizer.direction = UISwipeGestureRecognizerDirection.Right
        originView.addGestureRecognizer(showGestureRecognizer)

        let hideGestureRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
        hideGestureRecognizer.direction = UISwipeGestureRecognizerDirection.Left
        originView.addGestureRecognizer(hideGestureRecognizer)

    }

    func setupSideBar()


    {
        sidebarContainerView.frame = CGRectMake(-barWidth - 1, originView.frame.origin.y, barWidth, originView.frame.size.height)
        sidebarContainerView.backgroundColor = UIColor.clearColor()
        sidebarContainerView.clipsToBounds = false

        originView.addSubview(sidebarContainerView)

        let blurView:UIVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light))
        blurView.frame = sidebarContainerView.bounds
        sidebarContainerView.addSubview(blurView)

        sideBarTableViewController.delegate = self
        sideBarTableViewController.tableView.frame = sidebarContainerView.bounds
        sideBarTableViewController.tableView.clipsToBounds = false
        sideBarTableViewController.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
        sideBarTableViewController.tableView.backgroundColor = UIColor.clearColor()
        sideBarTableViewController.tableView.scrollsToTop = false
        sideBarTableViewController.tableView.contentInset = UIEdgeInsetsMake(sideBarTableViewTopInsert, 0, 0, 0)

        sideBarTableViewController.tableView.reloadData()

        sidebarContainerView.addSubview(sideBarTableViewController.tableView)
    }


    func handleSwipe(recognizer:UISwipeGestureRecognizer)

    {
        if recognizer.direction == UISwipeGestureRecognizerDirection.Left
        {
            showSideBar(false)
            delegate?.sideBarWillClose!()
        }
        else
        {
           showSideBar(true)
            delegate?.sideBarWillOpen!()
        }

        func showSideBar(shouldOpen:Bool)
        {

        }

    func sideBarControlDidSelectRow(indexPath: NSIndexPath)
        delegate?.sideBarDidSelectButtonAtIndex(indexPath.row)
    {

    }

我在第

行收到错误

class SideBar: NSObject, SideBarTableViewControllerDelegate {

有谁知道如何修复它?

1 个答案:

答案 0 :(得分:0)

您需要实施sideBarDidSelectButtonAtIndex(index:Int),因为它不是可选的。