有关segue和nsviewController的问题

发布于 2025-01-23 14:53:05 字数 1299 浏览 1 评论 0原文

我是迅速的新手,有一个问题。

我为客户提供了ViewController,其中包含一个列出了他们过去发票的桌面视图。当我双击发票时,它将打开详细说明事务的发票ViewController。我将发票号码从customervc转移到InvoICEVC,而且工作正常,除非InvoICEVC已经打开。这就是我必须解决的。

当InvoICEVC打开时:

  1. 我不确定InvoICEVC是否收到了segue。我试图打印发票号码,但等于INIT的0。
  2. 当激活InvoICEVC(类似于ViewDidload)时,可以使用一个函数,当InvoICEVC接收SEGUE时可以使用。如果已经打开。

这是客户端VC中的代码:

@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
}

这是发票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
        }

感谢您的帮助。

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:

  1. 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.
  2. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2025-01-30 14:53:05

该方法在这里使用通知解决了我的问题。

https://gist.github.com/ayakix/00a38f402f4bf3efb2c8acaad94b4616

The method post here, using notification, have solved my problem.

https://gist.github.com/ayakix/00a38f402f4bf3efb2c8acaad94b4616

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文