How to pass data between UIViewControllers with protocols/delegates

后端 未结 5 814

In the code below I have a ViewController(\"SenderViewController\"), which passes a message to the main ViewController when a button is tapped. Wha

5条回答
  •  春和景丽
    2020-12-17 01:21

    Objects don't exactly listen for method calls. They sit there, waiting to invoked.

    The line

    self.delegate?.messageData(inputMessage.text!)
    

    From your SenderViewController is a function call. (The term method and function are pretty much interchangeable, although the method is usually used for the functions of objects.) It invokes the function messageData in ViewController.

提交回复
热议问题