I am new in Swift and have a question.
I have ViewController for my customer with a included a tableView that list their past invoice. When I double click on an invoice, it open the Invoice ViewController that detail the transaction. I segue the invoice number from the CustomerVC to the InvoiceVC and it work just fine, except if the InvoiceVC is already open. This is what I have to solve.
When the InvoiceVC is open:
- I am not sure if InvoiceVC received the segue. I have tried to print the invoice number but its equal to 0 as it was init.
- Is there a function that can be used when the InvoiceVC is activated ( similar to viewDidLoad) that can be used when InvoiceVC receive a segue. if its already open.
Here is the code in the ClientVC:
@objc func tableViewDoubleClick(_ sender:AnyObject) {
if tableView.selectedRow >= 0 {
let srow = tableView.selectedRow
fact_nb = Int(fact_tbv[srow].id_f) ?? 0 // invoice nb that you want to segue
self.performSegue(withIdentifier: "gotofact", sender: nil) // segue identifier
}
}
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
let sb = segue.destinationController as! FacturesVC
print ("VCC569:", fact_nb)
sb.factnb = fact_nb
}
This is the code in the Invoice VC:
class FacturesVC: NSViewController, NSTextFieldDelegate,NSComboBoxDelegate, NSTableViewDelegate {
...
var factnb: Int = 0
...
func Load_DB( Lfact_ptr: Int) {
...
// if factnb correspong to an InvoiceNb - select that invoice...
if factnb == Int(facts_list[facts_select[i]].id_f) {
fact_ptr = facts_select[i]
factnb = 0
}
Thanks for your help.
The method post here, using notification, have solved my problem.
https://gist.github.com/ayakix/00a38f402f4bf3efb2c8acaad94b4616