-4

What's the code for calling viewDidLoad in UITextField, I only seem to find mixed answers:

    @IBOutlet weak var providerForm: UITextField!

// What to insert here to call the viewDidLoad function?

    override func viewDidLoad() {
    super.viewDidLoad()

    self.viewDidLoad()
    self.blockchain = Blockchain(genesisBlock: genesisBlock)
    // Do any additional setup after loading the view.
    self.generateDummyTransactions()
    self.providerForm = providerForm
    self.destinatorForm = destinatorForm
    self.amountSum = amountSum

func generateDummyTransactions() {



    let transaction = Transaction(from: "Mary", to: "Steve", amount: 20.0, transactionType: TransactionType.domestic)
    let block1 = Block()
    block1.addTransaction(transaction: transaction)
}
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
  • 2
    `viewDidLoad()` is the lifecycle method of all `UIViewController` and is called automatically. It is not called on any of the views, i.e. for any `UITextField`. Please clarify the requirement. – PGDev Feb 19 '20 at 14:54
  • I wanted a textfield called in the viewDidLoad(), as I have a send button which will launch app process – Guillaume Lauzier Feb 19 '20 at 15:13
  • textField called means? Do you want to call any method or anything in textField? – PGDev Feb 19 '20 at 15:14
  • Sorry, I edited and specified. Basically the app runs a on a print(generateDummyTransaction) function, but the generateDrummyTransaction is called from the viewDidLoad function, that's where I need the textfield input to be loaded when pressing a send button in the UIViewController – Guillaume Lauzier Feb 19 '20 at 15:17

1 Answers1

1

Call generateDummyTransactions() from sendButton's IBAction method and then fetch the textField's text there, i.e.

class VC: UIViewController {
    @IBOutlet weak var providerForm: UITextField!

    @IBAction func onTapSendButton(_ sender: UIButton) {
        self.generateDummyTransactions()
    }

    func generateDummyTransactions() {
        if let text = self.providerForm.text {
            //use text here...
        }
    }
}
PGDev
  • 23,751
  • 6
  • 34
  • 88