Home IOS Development ios – Delegate is nil when passing information again to VC

ios – Delegate is nil when passing information again to VC

0
ios – Delegate is nil when passing information again to VC

[ad_1]

Here is my instance utilization of delegate programmatically. The code passes a message from one view to different view controller. I’ve two view SendMessageController and Obtain message controller. It is passing information again situation.

Protocol is outlined in SendMessageController.

protocol SendMessageDelegate: AnyObject {
    func message(textual content: String)
}
closing class SendMessageController: UIViewController {
        
    weak var delegate: SendMessageDelegate?
    
    

    @objc func button() {
        sendMessage()  
    }

    func sendMessage() {
       let message = “Good day World”
       delegate?.message(textual content: message)
       print("Delegate is :(delegate)")
       print("self:(self)")   
} 

In Present Message View Controller which receives message:

closing class ShowMessageController: UIViewController,SendMessageDelegate {
     
    let sendMessageController = SendMessageController() 
     
    override func viewDidLoad() {
        sendMessageController.delegate = self
        print("(sendMessageController)")
    }
    
    func message(textual content: String) {
        print(“The message is:(textual content)”)
             
    }       
}
  

The delegates prints nil, and reminiscence deal with of print(self) is completely different than print(“(sendMessageController)”).
I had use delegate earlier than the place reminiscence adress of SendVC have been similar, do not know what is occurring right here.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here