I have a NSViewController
with multiple NSComboBox
instances.
I have the following code that adds the items to the NSComboBox
and then selects an item:
@IBOutlet weak var monitors: NSComboBox!
fileprivate func fillMonitors()
{
self.monitors.removeAllItems()
var items: [String] = []
for screen in NSScreen.screens
{
items.append(screen.localizedName)
}
self.monitors.addItems(withObjectValues: items)
guard let primaryMonitor = self.configuration?.layout.displayName ?? NSScreen.main?.localizedName else { return }
if let index = items.firstIndex(of: primaryMonitor)
{
self.monitors.selectItem(at: index)
}
}
The items are added and the correct monitor is found which means that the following line selects the proper monitor:
self.monitors.selectItem(at: index)
However, the NSComboBox does not display any text whatsoever. Also, the opening of the dropdown feels very weird, sometimes it's closing again, but then it works properly.
When selecting another item, the event handler is called and the value is processed, so I don't think that this is a bug in my code. Has anyone experienced this before? I have tried to set the text directly using the stringValue
but it also does not work. I am really lost here. Really appreciate any hints. I am not using a datasource (property set to false), the delegate
is nil.
Using Ventura with Xcode 14.1 RC2.