Ios Swift中的委托模式不带Segue

Ios Swift中的委托模式不带Segue,ios,swift,xcode,delegates,Ios,Swift,Xcode,Delegates,我找不到没有segue的Swift委托模式示例。我希望boss类(boss视图)向worker类(worker视图)发送命令,并打印boss要打印的内容。当我按下boss页面上的任意一个按钮(doThisButton/doThatButton)时,代表显示为“无” 编辑:我的视图设置如下:“TheBoss”VC有三个按钮,“Dothis”按钮、“DoHatButton”和“goToTheWorker”按钮。“TheWorker”VC有一个文本框。“doThisButton”/“doThatBut

我找不到没有segue的Swift委托模式示例。我希望boss类(boss视图)向worker类(worker视图)发送命令,并打印boss要打印的内容。当我按下boss页面上的任意一个按钮(doThisButton/doThatButton)时,代表显示为“无”

编辑:我的视图设置如下:“TheBoss”VC有三个按钮,“Dothis”按钮、“DoHatButton”和“goToTheWorker”按钮。“TheWorker”VC有一个文本框。“doThisButton”/“doThatButton”会将信息发送到“TheWorker”VC中的文本框,但不会使“TheWorker”VC出现。“goToTheWorker”按钮是在情节提要中设置的一个显示序列,用于打开“TheWorker”VC。

这是“老板”班

import UIKit

protocol TheBossesOrdersDelegate {
    func doThis(numberOne: Int, stringOne: String)
    func doThat(numberTwo: Int, stringTwo: String)
}

class TheBoss: UIViewController {

    // Declair Delegate
    var delegate: TheBossesOrdersDelegate!

    @IBAction func doThisButton(_ sender: UIButton) {
        delegate.doThis(numberOne: 75, stringOne: "Do This")
    }
    @IBAction func doThatButton(_ sender: UIButton) {
        delegate.doThat(numberTwo: 125, stringTwo: "Do That")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}
这是“工人”班

import UIKit

class TheWorker: UIViewController, TheBossesOrdersDelegate {

    let theBoss = TheBoss()

    func doThis(numberOne: Int, stringOne: String) {
        print("the boss send this number to print: \(numberOne) and this string: \(stringOne)")
        theWorkersTextBox.text = "Number: \(numberOne) String:\(stringOne)"
    }

    func doThat(numberTwo: Int, stringTwo: String) {
        print("the boss send this number to print: \(numberTwo) and this string: \(stringTwo)")
        theWorkersTextBox.text = "Number: \(numberTwo) String:\(stringTwo)"
    }

    @IBOutlet weak var theWorkersTextBox: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        theBoss.delegate = self
    }
}

看起来你的代码让工人创建了老板。既然你这样做了,你就需要告诉老板你的代表是谁:

import UIKit

class TheWorker: UIViewController, TheBossesOrdersDelegate {


    let theBoss = { 
      let result = TheBoss()
      result.delegate = self  //This is the line you are missing
      return result
    }()

//The rest of your TheWorker class's code...
}
编辑:
根据你的评论,你有一团混乱。发布显示辅助视图控制器的按钮的Boss类代码。你的标题上写着“w/o segue”,但在你的评论中你说“老板首先出现,并包含一个按钮,通过show segue连接到工人”“什么?你说没有一段话。

工人VC是如何创建和呈现的?还是老板?哪一个是第一个以及它们是如何连接的?两者都嵌入在导航控制器中,首先显示的是boss,并包含一个通过显示序列连接到工人的按钮。等等,什么?老板把工人关在板条箱里?那么为什么在
TheWorker
类中有代码来创建boss的新实例呢?那没有道理。你的问题和你的评论互相矛盾。你需要更清楚地描述你的问题,否则我们帮不了你。