gpt4 book ai didi

swift - presenter 函数在 swift 3 上永远不会被读取

转载 作者:行者123 更新时间:2023-11-28 14:20:23 25 4
gpt4 key购买 nike

我正在调用我的演示者功能,它列在我的演示者正在实现的协议(protocol)中,但无论何时我调用它,它都不会进入内部,我如何初始化我的演示者以便我可以调用界面函数?

这是我的 View Controller :

import UIKit

class FirstScreenViewController: UIViewController, MainViewProtocol {

var myPresenter: MainPresenterProtocol?

func outputPresenterFunction() {
print (myPresenter?.presenterProtocolFuncTwo(numOne: 2, numTwo: 4, sucssesMessage: "Made it ?", failMessage: "failed :(" ) ?? "Default landed")
}

}

在我的演示者中我有:

import Foundation

class MainPresenter: MainPresenterProtocol {

var screenViewController: MainViewProtocol?

func presenterProtocolFuncTwo(numOne: Int, numTwo: Int, sucssesMessage: String, failMessage: String) -> String {
print("function is called")
return "presenter function is called sussfuly"
}

}

和我的协议(protocol)本身:

protocol MainViewProtocol {
func showSmallHeadline(textToShow: String)
func showHeadline(textToShow: String)
}

protocol MainPresenterProtocol {
static func presenterProtocolFuncOne()
func presenterProtocolFuncTwo(numOne: Int, numTwo: Int, sucssesMessage: String, failMessage: String) -> String
func presenterProtocolFucThree () -> Bool
}

每当我调用 presenterProtocolFuncTwo 时,我都会得到我的默认值,它不会进入我的演示者的函数中

最佳答案

您应该使用 myPresenterscreenViewController 属性来使用它们。

protocol MainViewProtocol: class { ... }

class FirstScreenViewController: UIViewController, MainViewProtocol {
var myPresenter: MainPresenterProtocol?

override func viewDidLoad() {
super.viewDidLoad()
myPresenter = MainPresenter(controller: self)
}
}

class MainPresenter: MainPresenterProtocol {
weak var screenViewController: MainViewProtocol?

init(controller: MainViewProtocol) {
screenViewController = controller
}
}

关于swift - presenter 函数在 swift 3 上永远不会被读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51964077/

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