SelectedObject of PopUpButton

I want to set the selection of a PopUpButton at start to my Defaults,
but the first is to control al the aspects of the PopUpButton.

Controlling the changes of the user is easy setting the selection of one item of the PopUpButton to a function,
the complex is to control the PopUpButton from code/UI.

I have this test_project to test the SelectObject from code or UI.
Once property B_years_selected (Selected Object) is set, it can’t be edited?!?!?!?!

script test_PopUpButtonAppDelegate
	property parent : class "NSObject"
	
	property mainWindow : missing value
--Binded to Content of the PopUpButton of the UI
	property B_years : {2012, 2013, 2014, 2015} --> works great
--Binded to Selected Object of the PopUpButton of the UI
	property B_years_selected : 2012 --> works great
	
	on applicationWillFinishLaunching_(aNotification)
		set B_years_selected to 2014 --> does not work
		
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		return current application's NSTerminateNow
	end applicationShouldTerminate_
end script

I have tried everything i found to pre select an item of the PopUpButton, but nothing works.
Thanks for advance. :slight_smile:

Browser: Safari 534.57.2
Operating System: Mac OS X (10.8)

Hi,

to conform to key-value coding set the property via the accessor method by adding my


set my B_years_selected to 2014

It works!! :o

Can’t believe it.

I just lost a lot of time on something so ridiculous.

THANK YOU :lol:

It works only on the test_project! :frowning:

In my real project i have 2 .XIB.
One of them (the second) has the option screen where the PopUpButton is located.

Doing the same as in the test_project, it doesn’t change the Selected Object.

set my B_year_selected_value

Changes the variable but nothing happens on the Button!!

The bindings are the same.

Please help

The bindings can’t be the same. Your app delegate will not even show up in the “Bind to” popup of the second .xib because the instance belongs to a different .xib. You just can’t bind across .xibs like that.

It’s true.
Navigating through all the information on these fantastic forums,
I found someone saying to be not afraid to use multiple UI’s.

After changing everything to one UI, all the code worked right the first time.

Thanks to people like you, I never go to bed without knowing something new.

Thanks for being there. :lol: