有关segue和nsviewController的问题
我是迅速的新手,有一个问题。
我为客户提供了ViewController,其中包含一个列出了他们过去发票的桌面视图。当我双击发票时,它将打开详细说明事务的发票ViewController。我将发票号码从customervc转移到InvoICEVC,而且工作正常,除非InvoICEVC已经打开。这就是我必须解决的。
当InvoICEVC打开时:
- 我不确定InvoICEVC是否收到了segue。我试图打印发票号码,但等于INIT的0。
- 当激活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:
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法在这里使用通知解决了我的问题。
https://gist.github.com/ayakix/00a38f402f4bf3efb2c8acaad94b4616
The method post here, using notification, have solved my problem.
https://gist.github.com/ayakix/00a38f402f4bf3efb2c8acaad94b4616