4

I want to change the title of the MenuItem after the login process has been completed successfully and once the user logs off.

But if I log in and check the title of the menu item, it has not changed. I have even tried to hide it, with no success.

This is my code

var mainMenu:NSMenu
var LoginButton:NSMenuItem
mainMenu=NSApplication.sharedApplication().mainMenu!
LoginButton=mainMenu.itemWithTitle("Login")!
LoginButton.title="LogOff"
LoginButton.hidden=true

Thanks for any help.

pkamb
  • 33,281
  • 23
  • 160
  • 191
JRR
  • 41
  • 2

1 Answers1

7

Bind the Title parameter of the menu item in Interface Builder / Bindings Inspector (⌥⌘7) to a property with dynamic attribute in AppDelegate.

For example declare in AppDelegate

@objc dynamic var logonTitle = "Login"

and bind the Title parameter of the menu item to AppDelegate > Model Key Path logonTitle

Now whenever you change the value of logonTitle the title changes accordingly.

No further references, outlets etc. needed.

PS: Please name your variables consistently starting with a lowercase letter as recommended in the Guidelines.

vadian
  • 274,689
  • 30
  • 353
  • 361