Re: Simple IB Question...
Re: Simple IB Question...
- Subject: Re: Simple IB Question...
- From: Ondra Cada <email@hidden>
- Date: Fri, 27 Jul 2001 23:20:09 +0200
Ryan,
>
>>>>> email@hidden (RE) wrote at Fri, 27 Jul 2001 16:53:07 -0400:
RE> I'm new to Cocoa and the Apple tools, so I thought that maybe someone
RE> with more experience than me might be able to help. I was trying to make
RE> a simple little test GUI in IB that had a slider and 2 text fields. I
RE> tried to connect the slider to both text fields so they could both get
RE> the value of the slider using the 'target->takeIntValueFrom' connection
RE> option. However, whenever I make one connection it always undoes the
RE> other one!
Yep, that's true.
The thing is that the wire magic, in fact, is nothing more than
(i) setting the slider's property variable 'target' to the target object
(TextField here);
(ii) setting the slider's property variable 'action' to the
"takeIntValueFrom:" message name (actually a selector, but you don't need to
know the difference for months yet ;)
(To further explain how and why it works: whenever the slider is changed, it
"sends action to target" -- it checks which object is referenced by its
property 'target' and sends it the message from 'action'. Well, so the
TextField gets the "takeIntValueFrom:" message, which literally makes it to
take the value from the object who sent the message -- ie., from the slider.)
Back to the problem: if you drag another wire -- ie. set those two variables
to a new pair of values -- the older 'wire' (ie. the previous values)
naturally disappear.
RE> Can someone please give me some advice on what I'd need to do to make
RE> this setup work?
Unless you get a smart palette like the old MiscKit one for NeXTStep (so far
as I know, there is nothing alike for OS X yet; it allowed you to make
visually just the same trick we'll do programmatically here) you have to do
that in code: make a controller object with an action "takeIntValueFrom:"
(you can name it otherwise if you want to) and two outlets, "field1" and
"field2". Bind the slider's target to the _controller's_ "takeIntValueFrom:",
bind the outlets to the text fields.
Now just implement the method this way:
-(void)takeIntValueFrom:sender {
[field1 setIntValue:[sender intValue]];
[field2 setIntValue:[sender intValue]];
}
It should work properly.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc