ViewController 不符合自定义 UIButton Class
ViewController not conforming to a custom UIButton Class
我有一个自定义 UIButton class,我正尝试将其导入到我的项目中的 ViewController class,但我收到错误消息:'ViewController' 不符合协议 'OverrideButtonDelegate'"
这是来自自定义 UIButton 的代码 Class:
import Foundation
import UIKit
protocol OverrideButtonDelegate: NSObjectProtocol {
func overrideButtonDidStartPress(overrideButton: OverrideButton)
func overrideButtonDidEndPress(overrideButton: OverrideButton)
}
class OverrideButton: UIButton {
var delegate: OverrideButtonDelegate?
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
delegate?.overrideButtonDidStartPress(self)
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
delegate?.overrideButtonDidEndPress(self)
}
}
这里是 ViewController 的代码,我在其中收到错误消息 "Type 'ViewController' does not conform to protocol 'OverrideButtonDelegate'"
class ViewController: UIViewController, OverrideButtonDelegate {
你在UIViewController的delegate中定义了这两个函数吗? 当class符合协议时,协议中的功能必须在class
中实现
class ViewController: UIViewController, OverrideButtonDelegate {
func overrideButtonDidStartPress(overrideButton: OverrideButton)
{
//Code
}
func overrideButtonDidEndPress(overrideButton: OverrideButton)
{
//Code
}
}
我有一个自定义 UIButton class,我正尝试将其导入到我的项目中的 ViewController class,但我收到错误消息:'ViewController' 不符合协议 'OverrideButtonDelegate'"
这是来自自定义 UIButton 的代码 Class:
import Foundation
import UIKit
protocol OverrideButtonDelegate: NSObjectProtocol {
func overrideButtonDidStartPress(overrideButton: OverrideButton)
func overrideButtonDidEndPress(overrideButton: OverrideButton)
}
class OverrideButton: UIButton {
var delegate: OverrideButtonDelegate?
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
delegate?.overrideButtonDidStartPress(self)
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
delegate?.overrideButtonDidEndPress(self)
}
}
这里是 ViewController 的代码,我在其中收到错误消息 "Type 'ViewController' does not conform to protocol 'OverrideButtonDelegate'"
class ViewController: UIViewController, OverrideButtonDelegate {
你在UIViewController的delegate中定义了这两个函数吗? 当class符合协议时,协议中的功能必须在class
中实现class ViewController: UIViewController, OverrideButtonDelegate {
func overrideButtonDidStartPress(overrideButton: OverrideButton)
{
//Code
}
func overrideButtonDidEndPress(overrideButton: OverrideButton)
{
//Code
}
}