Swift 3:无法将'CircleMenu'类型的值转换为预期的参数类型'CircleMenu'

时间:2016-12-17 03:40:07

标签: ios swift xcode delegates

我有一个UIButton的自定义按钮子类

/// A Button object with pop ups buttons
open class CircleMenu: UIButton {
  /// The object that acts as the delegate of the circle menu.
  @IBOutlet weak open var delegate: /*AnyObject?*/ CircleMenuDelegate?

......................

在同一个班级中,有一个功能可以检测何时选择一个按钮。

func buttonHandler(_ sender: CircleMenuButton) {
    guard let platform = self.platform else { return }
    self.delegate?.circleMenu?(self, buttonWillSelected: sender, atIndex: sender.tag)
    let circle = CircleMenuLoader(radius: CGFloat(distance),
                                  strokeWidth: bounds.size.height,
                                  platform: platform,
                                  color: sender.backgroundColor)

    if let container = sender.container { // rotation animation
      sender.rotationAnimation(container.angleZ + 360, duration: duration)
      container.superview?.bringSubview(toFront: container)
    }

    if let buttons = buttons {
      circle.fillAnimation(duration, startAngle: -90 + Float(360 / buttons.count) * Float(sender.tag)) { [weak self] _ in
        self?.buttons?.forEach { $0.alpha = 0 }
      }
      circle.hideAnimation(0.5, delay: duration) { [weak self] _ in
        if self?.platform?.superview != nil { self?.platform?.removeFromSuperview() }
      }

      hideCenterButton(duration: 0.3)
      showCenterButton(duration: 0.525, delay: duration)

      if customNormalIconView != nil && customSelectedIconView != nil {

        DispatchQueue.main.asyncAfter(deadline: .now() + duration, execute: {
          self.delegate?.circleMenu?(self, buttonDidSelected: sender, atIndex: sender.tag)

        })
      }
    }
  }

使用上面的委托变量,我有另一个类来管理委托。

@objc public protocol CircleMenuDelegate {
    @objc optional func circleMenu(_ circleMenu: CircleMenu, buttonWillSelected sender: UIButton, atIndex: Int)
}

我正在尝试访问数据,特别是在另一个类中按下的按钮的索引,就在我正在玩的时候如果在按钮内设置它

class AppMainViewController: UIViewController, CircleMenuDelegate  {

    @IBAction func getValue(_ sender: Any) {
        CircleMenuDelegate.circleMenu(CircleMenu, buttonWillSelected: UIButton, atIndex: Int)
    }
}

这给我一个错误“无法将'CircleMenu'类型的值转换为预期的参数类型'CircleMenu'”

------ ------ EDIT

在AppMainViewController类的函数中添加circleMenu调用会停止上面的类型错误,但后来我不知道如何获取buttonWillSelected和atIndex的值。

func circleMenu(_ cm: CircleMenu, buttonWillSelected sender: UIButton, atIndex: Int) {
    print(sender.tag)
}

另外一些教科书,在线搜索显示类似于:

CircleMenu().delegate = self

但是在CircleMenu()。dropdown options

之后没有选择委托的选项

1 个答案:

答案 0 :(得分:0)

我怀疑您在委托方法调用中传递类名import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View } from 'react-native'; import MapView from 'react-native-maps'; export default class Haulr extends Component { render() { return ( <MapView initialRegion={{ latitude: 37.78825, longitude: -122.4324, latitudeDelta: 0.0922, longitudeDelta: 0.0421, }} /> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, map: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, }, }); AppRegistry.registerComponent('Haulr', () => Haulr); 而不是CircleMenu类的对象。

CircleMenu