从 Swift 5 / Cocoa 中的 tableView 从一个故事板转到另一个故事板

发布于 2025-01-12 05:23:53 字数 1173 浏览 4 评论 0原文

搜索该主题但找不到有效的解决方案。

我正在构建一个带有多个故事板的会计应用程序。主要、客户(客户)、发票(事实)...等。我可以通过单击按钮从主故事板转到发票故事板的客户,没问题...按钮(主 SB)链接到客户或发票故事板参考。

在客户故事板中,我有一个表视图,其中列出了该客户的购买历史记录。我希望能够双击特定发票,并在发票情节提要中打开该发票。

双 CLI 部分工作正常,打印消息工作...但程序崩溃后显示消息:无法将类型 '__NSCFBoolean' (0x7fffaab000c8) 的值转换为 '__C.NSViewControllerPresentationAnimator' 该代码是从另一篇文章中获取并改编的。我尝试了不同的变体但没有成功,即相同的错误消息。

我还没有从事将发票号码从客户端 SB 传输到发票 SB 的部分。我可能会使用 segue 传输发票编号,并让发票程序在加载

发票故事板文件名:factures.storyboard 后查看该变量是否为 nil。 制造视图控制器类:FacturesVC ViewControllerstoryboardID:facturesVC_id

    @objc func tableViewDoubleClick(_ sender:AnyObject) {

    if  tableView.selectedRow >= 0 {
          
        print ("VC545:", tableView.selectedRow)
         
        //let storyboard = NSStoryboard(name: "factures", bundle: nil)
        //let VC = storyboard.instantiateViewController(withIdentifier: "facturesVC_id")   // give same error
 
        let VC = NSStoryboard(name: "factures", bundle: nil).instantiateController(withIdentifier: "facturesVC_id") as! FacturesVC
        self.present(VC as NSViewController, animator: true as! NSViewControllerPresentationAnimator)

        }
    }

have search on that topic without finding a solution that work.

I am building a accounting application with several storyboard. Main, Customer( clients), invoice (factures)... etc. I can go from the main storyboard to the customer of Invoice storyboard by click a button no problem... The button (main SB) is linked to the Customer or Invoice storyboard reference.

In the clients storyboard, I have a tableView with that list the purchased historic of that customer. I would like to to be able to double clic on a specific invoice, and open that invoice in the Invoice storyboard.

The double clic part work fine, print message work... but the program crash after with the message: Could not cast value of type '__NSCFBoolean' (0x7fffaab000c8) to '__C.NSViewControllerPresentationAnimator'
That code was taken andadapted from another post. I have tried different variation withou success ie same error message.

I have not work on the part where I transfer the Invoice number from the client SB to the Invoice SB. I will likely transfer the Invoice number with a segue and have the Invoices program look if that variable if not nil, after loading

Invoice storyboard filename : factures.storyboard
facture ViewController Class : FacturesVC
ViewController storyboardID : facturesVC_id

    @objc func tableViewDoubleClick(_ sender:AnyObject) {

    if  tableView.selectedRow >= 0 {
          
        print ("VC545:", tableView.selectedRow)
         
        //let storyboard = NSStoryboard(name: "factures", bundle: nil)
        //let VC = storyboard.instantiateViewController(withIdentifier: "facturesVC_id")   // give same error
 
        let VC = NSStoryboard(name: "factures", bundle: nil).instantiateController(withIdentifier: "facturesVC_id") as! FacturesVC
        self.present(VC as NSViewController, animator: true as! NSViewControllerPresentationAnimator)

        }
    }

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

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

发布评论

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

评论(2

凉城凉梦凉人心 2025-01-19 05:23:53

你的代码没有意义。

您似乎正在尝试调用 present(_:animator:)。如果您调用它,则需要向其传递一个动画器(NSViewControllerPresentationAnimator 类型的对象。)。

您的代码不会创建 NSViewControllerPresentationAnimator

以下是您需要如何更改它的概述:

    let vc = NSStoryboard(name: "factures", bundle: nil).instantiateController(withIdentifier: "facturesVC_id") as! FacturesVC
    let animator = // Code to create an NSViewControllerPresentationAnimator

    self.present(vc, animator: animator)

我以前没有使用过 NSViewControllerPresentationAnimator 。 (这些天我主要使用 iOS。)如果您不确定如何继续,您可能应该搜索有关 NSViewControllerPresentationAnimator 的教程。

Your code does not make sense.

It looks like you are trying to call present(_:animator:). If you call that, you need to pass it an animator (an object of type NSViewControllerPresentationAnimator.)

Your code does not create a NSViewControllerPresentationAnimator.

Here is an outline of how you need to change it:

    let vc = NSStoryboard(name: "factures", bundle: nil).instantiateController(withIdentifier: "facturesVC_id") as! FacturesVC
    let animator = // Code to create an NSViewControllerPresentationAnimator

    self.present(vc, animator: animator)

I haven't worked with NSViewControllerPresentationAnimators before. (I mostly work with iOS these days.) You should probably search for tutorials on NSViewControllerPresentationAnimator if you are unsure how to proceed.

百善笑为先 2025-01-19 05:23:53

终于,我找到了我一直在寻找的答案......
这是代码。

 
    @objc func tableViewDoubleClick(_ sender:AnyObject) {

    if  tableView.selectedRow >= 0 {
        
        let srow = tableView.selectedRow
        //print ("VC551:", srow)
        
        fact_nb = Int(fact_tbv[srow].id_f) ?? 0  // invoice nb that you want to segue
          
        let storyboard = NSStoryboard(name: "factures", bundle: nil)
        let VC = storyboard.instantiateController(withIdentifier: "facturesVC_id")
        
        //self.presentAsSheet(VC as! NSViewController)   work fine for sheet
       // self.presentingViewController    // data are laoded but nothing show up
       // self.presentAsModalWindow(VC as! NSViewController) // OK for modal, cannot be resize , yellow button missing on bar
         // self.present(VC as! NSViewController, animator: false as! NSViewControllerPresentationAnimator)   // true or false... need a animator
        
        let window = NSWindow(contentViewController: VC as! NSViewController)
        window.center()
        let windowController = NSWindowController(window: window)
        windowController.showWindow(nil)

         //see How to Perform Segue https://www.youtube.com/watch?v=JL0xuZ4TXrM 
        self.performSegue(withIdentifier: "gotofact", sender: nil)   // segue identifier name : gotofact
  
        }
    }
    override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
        let sb = segue.destinationController as! FacturesVC
        print ("VC569:", fact_nb)
        
        sb.factnb = fact_nb
    }
         
 

        
    

Finally, I have found the answer I was looking for...
Here is the code.

 
    @objc func tableViewDoubleClick(_ sender:AnyObject) {

    if  tableView.selectedRow >= 0 {
        
        let srow = tableView.selectedRow
        //print ("VC551:", srow)
        
        fact_nb = Int(fact_tbv[srow].id_f) ?? 0  // invoice nb that you want to segue
          
        let storyboard = NSStoryboard(name: "factures", bundle: nil)
        let VC = storyboard.instantiateController(withIdentifier: "facturesVC_id")
        
        //self.presentAsSheet(VC as! NSViewController)   work fine for sheet
       // self.presentingViewController    // data are laoded but nothing show up
       // self.presentAsModalWindow(VC as! NSViewController) // OK for modal, cannot be resize , yellow button missing on bar
         // self.present(VC as! NSViewController, animator: false as! NSViewControllerPresentationAnimator)   // true or false... need a animator
        
        let window = NSWindow(contentViewController: VC as! NSViewController)
        window.center()
        let windowController = NSWindowController(window: window)
        windowController.showWindow(nil)

         //see How to Perform Segue https://www.youtube.com/watch?v=JL0xuZ4TXrM 
        self.performSegue(withIdentifier: "gotofact", sender: nil)   // segue identifier name : gotofact
  
        }
    }
    override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
        let sb = segue.destinationController as! FacturesVC
        print ("VC569:", fact_nb)
        
        sb.factnb = fact_nb
    }
         
 

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