类型“viewController”不符合协议“PathMenuDelegate”

时间:2016-07-02 01:38:28

标签: ios swift cocoapods

  • 我刚开始学习swift。
  • 我安装了Cocoapod并试图看看我是否可以实施。
  • 我真的不知道如何解决这个问题,其余的代码将在下面提供。

    override func viewDidLoad() {
    super.viewDidLoad()
    
    
    
    let menuItemImage = UIImage(named: "bg-menuitem")!
    let menuItemHighlitedImage = UIImage(named: "bg-menuitem-highlighted")!
    
    let starImage = UIImage(named: "icon-star")!
    
    let starMenuItem1 = PathMenuItem(image: menuItemImage, highlightedImage: menuItemHighlitedImage, contentImage: starImage)
    
    let starMenuItem2 = PathMenuItem(image: menuItemImage, highlightedImage: menuItemHighlitedImage, contentImage: starImage)
    
    let starMenuItem3 = PathMenuItem(image: menuItemImage, highlightedImage: menuItemHighlitedImage, contentImage: starImage)
    
    let starMenuItem4 = PathMenuItem(image: menuItemImage, highlightedImage: menuItemHighlitedImage, contentImage: starImage)
    
    let starMenuItem5 = PathMenuItem(image: menuItemImage, highlightedImage: menuItemHighlitedImage, contentImage: starImage)
    
    let items = [starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4, starMenuItem5]
    
    let startItem = PathMenuItem(image: UIImage(named: "bg-addbutton")!,
        highlightedImage: UIImage(named: "bg-addbutton-highlighted"),
        contentImage: UIImage(named: "icon-plus"),
        highlightedContentImage: UIImage(named: "icon-plus-highlighted"))
    
    let menu = PathMenu(frame: view.bounds, startItem: startItem, items: items)
    
    menu.delegate = self
    
    menu.startPoint = CGPointMake(UIScreen.mainScreen().bounds.width/2, self.view.frame.size.height - 30.0)
    menu.menuWholeAngle = CGFloat(M_PI) - CGFloat(M_PI/5)
    menu.rotateAngle = -CGFloat(M_PI_2) + CGFloat(M_PI/5) * 1/2
    menu.timeOffset = 0.0
    menu.farRadius = 110.0
    menu.nearRadius = 90.0
    menu.endRadius = 100.0
    menu.animationDuration = 0.5
    
    // Do any additional setup after loading the view, typically from a nib.
      }
    
       override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
     }
    
    
    }
    
  • 委托协议(PathMenuDelegate) _如何将下面显示的其余代码实现到viewDidLoad

     func pathMenu(menu: PathMenu, didSelectIndex idx: Int)
     func pathMenuDidFinishAnimationClose(menu: PathMenu)
     func pathMenuDidFinishAnimationOpen(menu: PathMenu)
     func pathMenuWillAnimateOpen(menu: PathMenu)
     func pathMenuWillAnimateClose(menu: PathMenu)
    

3 个答案:

答案 0 :(得分:1)

    
class ViewController: UIViewController{
    override func viewDidLoad() {
        super.viewDidLoad()
       ~~~
        menu.delegate = self
        self.view.addSubview(menu)
    }
}
extension ViewController: PathMenuDelegate {
    func didSelect(on menu: PathMenu, index: Int) {
        print("Select the index : \(index)")
    }
    func willStartAnimationOpen(on menu: PathMenu) {
        print("Menu will open!")
    }

    func willStartAnimationClose(on menu: PathMenu) {
        print("Menu will close!")
    }

    func didFinishAnimationOpen(on menu: PathMenu) {
        print("Menu was open!")
    }

    func didFinishAnimationClose(on menu: PathMenu) {
        print("Menu was closed!")
    }
}

答案 1 :(得分:0)

您无法将这些代码放入viewDidLoad。

使相应的viewController符合PathMenuDelegate

然后开始输入协议功能,您将获得有关'

的建议

答案 2 :(得分:0)

您提出质疑的所有内容,请在此处查看作者的示例代码:非常简单直接。这些委托的功能仅用于处理来自lib的事件。这里的示例只是打印一些东西向您展示,"您的代码可以正常工作"。

https://github.com/pixyzehn/PathMenu/blob/master/PathMenu-Sample/PathMenu-Sample/ViewController.swift