gpt4 book ai didi

ios - Swift 错误声明委托(delegate)

转载 作者:行者123 更新时间:2023-11-29 02:48:22 26 4
gpt4 key购买 nike

我是 swift 的新手,我正在研究委托(delegate)和协议(protocol)。在我的测试应用程序中,我使用此协议(protocol)声明(在 ViewController1 中),并且我有以下代码:

 import UIKit

//Protocol declaration

protocol viewController1Delegate

{

func didFinish(controller:ViewController1,text:String)
}

//ViewController1类

class ViewController1: UIViewController {

//delegate declaration for viewController1
var delegate:ViewController1? = nil


override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
valore.text=valoreInput
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func doneWithOK(sender: AnyObject) {

delegate?.didFinish(self,"done")
}
}

我的问题是 XCode 显示错误:ViewController1 没有名为 didFinisch 的成员。我的代码有什么问题?有人可以帮助我理解这个问题吗?

最佳答案

delegate 应该是 viewController1Delegate? 而不是 ViewController1?

关于ios - Swift 错误声明委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24837775/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com