Friday, November 6, 2026
HomeiOS Developmentios - not passing information to earlier controller

ios – not passing information to earlier controller

[ad_1]

import UIKit

protocol AddContactDelegate {
func addContact(contact: Contact)
}

class AddContacts: UIViewController{

var delegate: AddContactDelegate?

@IBOutlet weak var ContactTextField: UITextField!
@IBOutlet weak var nameTextField: UITextField!

override func viewDidLoad() {
    tremendous.viewDidLoad()
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .achieved, goal: self, motion: #selector(handleDone))
}

@objc func handleDone() {
    
    guard let fullname = nameTextField.textual content, nameTextField.hasText else {
        print("deal with error for title")
        return
    }
    
    guard let contactNumber = ContactTextField.textual content, ContactTextField.hasText else {
        print("deal with error for contact quantity")
        return
    }
    let contact = Contact(fullname: fullname, contactNumber: contactNumber)
    print(contact.fullname)
    print(contact.contactNumber)
    delegate?.addContact(contact: contact)
}

}

import UIKit

protocol AddContactDelegate {
func addContact(contact: Contact)
}

class AddContacts: UIViewController{

var delegate: AddContactDelegate?

@IBOutlet weak var ContactTextField: UITextField!
@IBOutlet weak var nameTextField: UITextField!

override func viewDidLoad() {
    tremendous.viewDidLoad()
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .achieved, goal: self, motion: #selector(handleDone))
}

@objc func handleDone() {
    
    guard let fullname = nameTextField.textual content, nameTextField.hasText else {
        print("deal with error for title")
        return
    }
    
    guard let contactNumber = ContactTextField.textual content, ContactTextField.hasText else {
        print("deal with erroe for contact quantity")
        return
    }
    let contact = Contact(fullname: fullname, contactNumber: contactNumber)
    print(contact.fullname)
    print(contact.contactNumber)
    delegate?.addContact(contact: contact)
}

}

i need to show an information which i’ve given to second controoler principally i need to cross information again to earlier controller however information is printing on console display however it’s not printing on earlier controller how am i able to remedy this challenge ?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments