I'm using Objective-C 2.0, in Mac Os X "Leopard" - does bindings work on it ?
Have you read the documentation on this material? The answers are
there, they really are.
Yes, I've created an NSButton, tagged it with IBOutlet and connected the outlet in IB.
I really mean "instance method"- and cannot assign value to the variable (contained in "if"-"else" statement) accordingly the checkbox is selected or not.
Kyle's Bindings suggestion is perfectly valid, but I think it's a
bad idea to try getting into that more advanced Cocoa technology when
you've clearly not mastered the basic architecture. That's not an
insult, just a reality: you have much yet to learn.
Specifically, you're trying to read the state of a control connected
to an outlet named "CheckBox", you aren't getting the result you want,
but you haven't demonstrated that you've tried the most basic
debugging to eliminate some common mistakes. Additionally, your
current coding habits (demonstrated in your original code listing)
show that you will probably run into trouble in the future as you try
more advanced Cocoa technologies (such as KVC/KVO/Bindings).
Some points:
1 - You should spend time looking at the Cocoa code formatting
conventions. You typically only capitalize class names. It should
probably be "checkBox". This formatting is used throughout Cocoa and
in some instances (KVC/KVO/Bindings) it's required that you follow it
for stuff to "just work".
2 - Have you verified (with the debugger or via NSLog()) that your
-calc: action is being called?
3 - You should always use constants when they're defined. For example,
-state returns NSMixedState , NSOnState, or NSOffState. Use those
constants (because their values *could* change in the future, though
it's admittedly not likely).
4 - In future posts, please be more explicit with your code examples.
I can guess that your -calc: action calls your -calc method, but
that's a guess. If it's an incorrect guess, than everybody's time
(including your own) is wasted in figuring that out. Post carefully
and you'll get careful answers.
5 - Read. The. Documentation. All documentation that's got anything to
do with your question. You'll probably save yourself a lot of time
(such as half a day's back-and-forth posting) by spending just 15 to
20 minutes reading a few documents or googling the documentation for
specific terms. It'll also make you a better developer (by "it", I
mean researching and learning how the reference material is structured
so you can find answers more quickly in the future).
Must say that I never had such a problem in other languages (Java, C++) which I've used before.
This has nothing at all to do with the language, but rather your
understanding of the overall architecture of the API you're using.
It's apparent from your first question above ("does bindings work on
...") that the primary reason for your lack of understanding is simply
not reading the documentation. If you haven't bothered reading the
documentation, of course you're going to have trouble using a
complicated technology. Cocoa is a big subject and no matter how
experienced you are with other APIs, you're not *that* good that you
don't have to read the documentation for a completely new one. :-D
It's all part of learning.
I think you'd do well to spend some more time going back over the
introductory Cocoa material. Don't give into the mistaken assumption
that "Cocoa basics" is equal to "Programming basics" ... even if
you're an experienced developer, if you're new to Cocoa (or any API),
you should still make sure you thoroughly understand the basics. Cocoa
follows a design pattern that is almost entirely alien to developers
who use other APIs. Likewise with Objective-C and other languages.
Both are "weird" by comparison to many others. Take your time, read as
much as you can, and try not to blame the API if you don't yet gasp
something. Chances are plenty of others use what you're struggling
with just fine - because they have experience. Instead, just read the
docs and ask the list for clarification.
--
I.S.