如何在 swift 中设置选项卡视图项的内容
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论