Difference running app within Xcode or directly

I have a NSDatePicker, text with stepper, installed as a statusbar item menu item view. Running this from XCode the date picker fields will highlight when selected, running the app directly from Finder the fields will not highlight even though they are selected and everything is working but the highlighting.


What is different that the highlighting works running from XCode?


I've had to subclass NSDatePicker to acceptFirstMouse(forEvent: NSEvent) and overridden mouseDown(with: NSEvent) and installed that as the menuItem's view but I can't get the fields to highlight as they re chosen.


Works great run from XCode, what's different?

Replies

Which version of XCode, of MacOS (understand that's a MacOS App).


Do other controls in the app hilite correctly ?


Could check the MacOS settings (General > Hilighting)

XCode Version 11.0 (11A420a)

Mac OS X Mohave 10.14.6


Everything works running from XCode and everything works running from Finder other than highlighting the fields of the date picker when they're clicked on, they're selected because keyboard actions and the stepper actions affect the field clicked on.


As I roll the mouse over the menu items they highlight, other the first one, there are four, that has the date picker installed as its view. That behavior is the same regardless of how the app is run. I'm just not highlighting the date picker fields and XCode is.


It has something to do with installing the date picker as the view of the menu item. I've tried now subclassing NSDatePicker and NSView and overriding anythingthat looks promising but I'm not great with the documentation or the code either I guess.


I've asked on the Cocoa dev forum and stackoverflow but no responses.

How did you set the menu autoEnableItems ?

menu.autoenablesItems = false


Thanks for your responses, I know it's tough not seeing any code, just not sure what would be relevant to post, it just a simple little thing, was trying to figureout writing a statusbar item. I thought it was a working as it should until I ran it from Finder.

If you're willing to take a look...


https://github.com/mswade0/Alarm

Could you explain in detail the setup.


It has something to do with installing the date picker as the view of the menu item


Which menu ?

Do you do it in IB or code ? If code, please post it.


How do you install the date picker as the view of the menu item ?

In IB ? In code ?

What do you mean by "install the date picker as the view of the menu item"

It's done in code. This line in function constructMenu: timeMenuItem.view = alarmView


func applicationDidFinishLaunching(_ aNotification: Notification) {

// Insert code here to initialize your application

let statusBar = NSStatusBar.system

let length:CGFloat = -1

statusBarItem = statusBar.statusItem(withLength: length)


statusBarItem.button?.image = NSImage(named: "fooalarm.png")

let statusBarMenu = NSMenu(title: "Alarm")

statusBarItem.menu = statusBarMenu

alarmTimePickerCellDelegate = AlarmTimePickerCellDelegateObj()

alarmView = .init(frame: NSRect(x: 0, y: 0, width: 200, height: 20))

alarmView.datePickerElements = NSDatePicker.ElementFlags.hourMinute

alarmView.datePickerStyle = .textFieldAndStepper

alarmView.delegate = alarmTimePickerCellDelegate

alarmView.dateValue = NSDate() as Date

constructMenu()


}


func constructMenu() {


timeMenuItem = NSMenuItem()


timeMenuItem.view = alarmView

startAlarmMnuItem = NSMenuItem(title: "Set Alarm", action: #selector(setAlarm), keyEquivalent: "s")

stopAlarmMnuItem = NSMenuItem(title: "Stop Alarm", action: #selector(stopAlarm), keyEquivalent: "S")

quitAlarmMnuItem = NSMenuItem(title: "Quit Alarm", action: #selector(quitAlarm), keyEquivalent: "q")

menu.addItem(timeMenuItem)

menu.addItem(startAlarmMnuItem)

menu.addItem(stopAlarmMnuItem)

menu.addItem(quitAlarmMnuItem)

menu.autoenablesItems = false

statusBarItem.menu = menu

stopAlarmMnuItem.isEnabled = false

}

>Works great run from XCode, what's different?


Not saying it's tied to your issue, but just a heads up that the basic difference is that when running via Xcode, the app is being run in debug mode. Things tend to run a bit slower, with different process hooks as you step thru the UI, etc. Might be something subtle or nothing all all in those cases.