gpt4 book ai didi

swift - 在 Swift Storyboards for mac 中从一个 NSViewController 切换到另一个 NSViewController

转载 作者:行者123 更新时间:2023-11-30 13:06:06 26 4
gpt4 key购买 nike

我有一个问题,我已经尝试解决很长一段时间了。还提供了项目文件。

所以我有以下想法,有一个带有按钮的侧边栏,当单击按钮时,它仅切换右侧内容。

我最初创建的项目只有 1 个 Storyboard。 Window 启动第一个 ViewController,其中包含按钮和自定义 View 。

我需要的是,当按下其中一个按钮时,自定义 View 将被另一个 ViewController 的内容替换。只是 View ,而不是整个先前的 View Controller 被另一个 View Controller 替换。

我该怎么做?赛格斯?层数?请迫切需要帮助,因为我无法弄清楚 Storyboard,但很想与他们合作。这将让我开始。

我想到的另一个选择是如果我使用 splitview 会更好吗?那么我可能可以用另一个完全正确的右侧 View Controller 替换右侧 View Controller ?

Link to project file in Xcode

My Storyboard

最佳答案

我用 textlable 创建这个,但是相同的。

  1. 创建“@IBOutlet weak var labelListInvoices:NSTextField!”
  2. 创建操作“@IBAction func onListInvoices(_ sender: AnyObject) { 让 act = InvoicesList(nibName: "InvoicesList", bundle: nil) app.show(行动!)"
  3. 创建一个 var "var app = NSApp.delegate as!AppDelegate"
  4. 现在转到 appdelegate 并创建此函数“//应用程序总监

    //使用://让 act = MainView(nibName: "MainView", bundle: nil)//应用程序.show(行动!)func show(_ newController: ControllerType, with message: 参数? = nil) { 让newView = newController.view

    if let frame = NSApp.mainWindow?.contentView?.frame {
    newView.frame = frame // Resize the view to the window instead
    }

    guard let main = NSApp.mainWindow?.contentViewController else { return }

    if main.childViewControllers.count < 1 { // if no controllers, then it's main controller
    main.addChildViewController(newController) // add new controller
    main.view.addSubview(newView) // add new view to main view
    if message != nil {
    newController.notify(message)
    }
    } else {
    let current = main.childViewControllers.last // get lasr controller as current before adding new
    main.addChildViewController(newController) // add new controller
    main.transition(from: current!, to: newController, options: [.crossfade]){
    if message != nil {
    newController.notify(message)
    }
    }
    }

    }“

关于swift - 在 Swift Storyboards for mac 中从一个 NSViewController 切换到另一个 NSViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39348786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com