简体   繁体   English

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

[英]type “viewController” does not conform protocol “PathMenuDelegate”

  • I just start learning swift. 我刚刚开始学习敏捷。
  • I installed Cocoapod and tried to see if i can implemented. 我安装了Cocoapod,并尝试查看是否可以实施。
  • i truly dont know how to fix this problem, the rest of the code will be provided down below. 我真的不知道该如何解决此问题,其余的代码将在下面提供。

     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. } } 
  • Delegate protocol (PathMenuDelegate) _ how to implement the rest of code show below into the viewDidLoad 委托协议(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) 
    
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!")
    }
}

You can't put these code in viewDidLoad. 您无法将这些代码放入viewDidLoad中。

Make the respective viewController conform to the PathMenuDelegate 使相应的viewController符合PathMenuDelegate

And Start typing the protocol functions you'll get suggestions for 'em 并开始键入协议功能,您将获得有关它们的建议

Everything you're questioning, just see the author's sample code here: Very simple and straight forward. 您要询问的所有内容,都可以在这里看到作者的示例代码:非常简单明了。 Those delegate's functions are just for handling events from the lib. 这些委托人的功能仅用于处理库中的事件。 And the sample here just prints something to show you that, "Your code works". 而且这里的示例只是打印出一些东西来向您显示“您的代码有效”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“ ViewController”不符合协议 - Type 'ViewController' does not conform to protocol Swift:类型'ViewController'不符合协议'UIPageViewControllerDataSource' - Swift: Type 'ViewController' does not conform to protocol 'UIPageViewControllerDataSource' 类型的viewcontroller不符合协议uitableviewdatasource - type viewcontroller does not conform to protocol uitableviewdatasource 类型“ ViewController”不符合协议“ FBSDKLoginButtonDelegate” - The type 'ViewController' does not conform to protocol 'FBSDKLoginButtonDelegate' ViewController类型不符合协议SKPaymentTransactiionObserver - type ViewController does not conform to protocol SKPaymentTransactiionObserver 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type “ViewController” does not conform to protocol 'UITableViewDataSource" 类型“ViewController”不符合协议“UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 类型'ViewController'不符合协议'UICollectionViewDataSource' - Type 'ViewController' does not conform to protocol 'UICollectionViewDataSource'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM