如何在 swift 中设置选项卡视图项的内容

发布于 2025-01-12 07:22:46 字数 547 浏览 1 评论 0原文

我在 Storyboard 中创建了一个选项卡视图,并在代码中创建了一个插座,每次用户单击按钮时,它都会创建一个新的选项卡项,其中包含 Web 视图。我还没有找到以编程方式设置选项卡内容的方法。有什么方法可以设置选项卡项的内容吗?

@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var tabView: NSTabView!


@IBAction func addTab(_ sender: Any) {
        let newTab = NSTabViewItem()
        //newTab.setContent(webView)
        tabView.addTabViewItem(newTab)
    }

还有另一个问题。当我尝试使用 addTab 函数创建新选项卡时,出现错误:

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

I created a tab view in storyboard, and created an outlet in my code, and every time a user clicks a button, it creates a new tab item that has a web view in it. I have not found a way to set the content of the tab programatically. Is there some way to set the content of the tab item?

@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var tabView: NSTabView!


@IBAction func addTab(_ sender: Any) {
        let newTab = NSTabViewItem()
        //newTab.setContent(webView)
        tabView.addTabViewItem(newTab)
    }

There's also another problem. When I try to create a new tab with the addTab function, I get an error :

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文