问题
This question may be very specific, but I'm new to all this and really need some help.
I'm building an iPhone synth app. I am using DCSliders an DCKnobs (they look nicer than the standard UISliders).
https://github.com/domesticcatsoftware/DCControls#readme
I am also working with libpd (a Pure Data library) so the audio DSP is handled by an embedded Pure Data patch.
https://gitorious.org/pdlib
I have got multiple DCSliders and DCKnobs in my interface. I am able to send control values from the sliders/knobs to Pure Data by making a class the delegate of the DCSlider...
- (void)loadView {
[super loadView];
self.mySlider = [[[DCSlider alloc] initWithDelegate:self] autorelease];
self.mySlider.frame = CGRectMake(10.0, 10.0, 20.0, 120.0);
[self.view addSubview:self.mySlider];
}
Then I implement a method to send control values to a receiver in Pure Data...
- (void)controlValueDidChange:(float)value sender:(id)sender {
[PdBase sendFloat:value toReceiver:@"beatvol"];
}
This all works ok.
The problem is that all of the sliders are sending the same control values.
How do I get each of the DCSliders to send independent control values to different receivers in Pure Data?
回答1:
You need to assign a tag to your sliders. Then in controlValueDidChange: you need to get that tag and do your actions according to the tags:
- (void)loadView
{
[super loadView];
mySlider = [[[DCSlider alloc] initWithDelegate:self] autorelease];
mySlider.frame = CGRectMake(10.0, 10.0, 20.0, 120.0);
mySlider.tag = 0;
[self.view addSubview: mySlider];
}
- (void)controlValueDidChange:(float)value sender:(id)sender
{
DCSlider * slider = (DCSlider *)sender;
switch (slider.tag)
{
case 0:
{
[PdBase sendFloat:value toReceiver:@"beatvol"];
}
break;
case 1:
{
/* do something for the 2nd slider */;
}
break;
}
}
来源:https://stackoverflow.com/questions/6869168/multiple-dcsliders-sending-different-control-values-xcode