Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NSToolbar灵活空间在Swift 5.x中不起作用_Swift_Xcode_Macos_Nstoolbar_Nstoolbaritem - Fatal编程技术网

NSToolbar灵活空间在Swift 5.x中不起作用

NSToolbar灵活空间在Swift 5.x中不起作用,swift,xcode,macos,nstoolbar,nstoolbaritem,Swift,Xcode,Macos,Nstoolbar,Nstoolbaritem,我使用Xcode 10.1(我相信是Swift 4.2)开发了这个应用程序,工具栏看起来不错: 但我将其移植到我的Xcode 11.6(我相信是Swift 5.2),现在工具栏上最右边的项目不再位于最右边: 在端口之前,我添加了加号按钮-复选框(ShowHidden)是最早的项目之一,此后从未更改。 此外,按钮的功能与预期相同-其动作正常。 注意:此应用程序不使用故事板或IB内容 由于我的代码被分割成几个文件(有很多不相关的代码),我将给出一个概述 class ToolbarControll

我使用Xcode 10.1(我相信是Swift 4.2)开发了这个应用程序,工具栏看起来不错:

但我将其移植到我的Xcode 11.6(我相信是Swift 5.2),现在工具栏上最右边的项目不再位于最右边:

在端口之前,我添加了加号按钮-复选框(ShowHidden)是最早的项目之一,此后从未更改。 此外,按钮的功能与预期相同-其动作正常。 注意:此应用程序不使用故事板或IB内容

由于我的代码被分割成几个文件(有很多不相关的代码),我将给出一个概述

class ToolbarController: NSObject, NSToolbarDelegate {

let toolbar = NSToolbar(identifier: NSToolbar.Identifier("toolbar"))
lazy var toolbarItem1: NSToolbarItem = {
    let toolbarItem = NSToolbarItem(itemIdentifier: NSToolbarItem.Identifier(rawValue: "Btn1"))
    let button = NSButton(frame: NSRect(x: 0, y: 0, width: 40, height: 1))
    button.target = self
   ...
    toolbarItem.view = button
    return toolbarItem
}() // defined as "lazy" to allow "self"
var toolbarItemSpace: NSToolbarItem = {
    let toolbarItem = NSToolbarItem(itemIdentifier: NSToolbarItem.Identifier.space)
    return toolbarItem
}()
 ...
var toolbarItemFlexSpace: NSToolbarItem = {
    let toolbarItem = NSToolbarItem(itemIdentifier: NSToolbarItem.Identifier.flexibleSpace)
    return toolbarItem
}()
lazy var toolbarItemShowHidden: NSToolbarItem = {
    let toolbarItem = NSToolbarItem(itemIdentifier: NSToolbarItem.Identifier(rawValue: "Checkbox"))
    let box = NSBox(frame: NSRect(x: 0, y: 0, width: 120, height: 40))
    let button = NSButton() // put in NSBox to use isolated action
  ...
    button.target = self
    box.contentView = button
    box.sizeToFit() // tightly fit the contents (button)
    toolbarItem.view = box
    return toolbarItem
}()
lazy var tbItems: [NSToolbarItem] = [toolbarItem1, ...]
该类定义工具栏、添加项、实现所有这些工具栏(委托)方法并使其成为委托。然后,将NSWindowController设置为应用程序工具栏

有人能看到我的代码中导致上述问题的问题吗? 否则,这是一个错误吗?

请发布一个。请发布一个。