switch 语句中只有 1 种情况有效(目标 C)
我正在 Xcode 中开发合成器应用程序。我正在使用自定义滑块和旋钮。我希望它们将控制值发送到嵌入式纯数据补丁中的接收器(我使用 libpd 作为纯数据库和包装器)。
我的界面上有多个自定义滑块和旋钮。我希望每个人只发送自己的控制值,独立于其他滑块/旋钮。
我正在使用标签和 switch 语句。 问题是只有第一种情况可以工作,并且所有滑块和旋钮都将控制值发送到同一接收器。
- (void)viewDidLoad {
[super viewDidLoad];
// Slider 1
slider.tag = 0;
slider = [[[DCSlider alloc] initWithDelegate:self] autorelease];
slider.frame = CGRectMake(0,0,20,100);
[self.sliderContainer addSubview: slider];
// Slider 2
slider2.tag = 1;
slider2 = [[[DCSlider alloc] initWithDelegate:self] autorelease];
slider2.frame = CGRectMake(0,0,20,100);
[self.sliderContainer2 addSubview: slider2];
}
然后我在这里实现该方法...
- (void)controlValueDidChange:(float)value sender:(id)sender {
DCSlider *slidertag = (DCSlider *)sender;
switch (slidertag.tag)
{
case 0:
{
[PdBase sendFloat:value toReceiver:@"beatvol"];
}
break;
case 1:
{
[PdBase sendFloat:value toReceiver:@"bassvol"];
}
break;
}
}
有人可以帮忙吗?谢谢。
I am working in Xcode on a synthesizer application. I am using custom sliders and knobs. I want these to send control values to receivers in an embedded Pure Data patch (I am using libpd as a Pure Data library and wrapper).
I have multiple custom sliders and knobs on my interface. I want each one to send only their own control values independently of the other sliders/knobs.
I am using tags and a switch statement.
The problem is that only the first case is working and all of the sliders and knobs are sending control values to the same receiver.
- (void)viewDidLoad {
[super viewDidLoad];
// Slider 1
slider.tag = 0;
slider = [[[DCSlider alloc] initWithDelegate:self] autorelease];
slider.frame = CGRectMake(0,0,20,100);
[self.sliderContainer addSubview: slider];
// Slider 2
slider2.tag = 1;
slider2 = [[[DCSlider alloc] initWithDelegate:self] autorelease];
slider2.frame = CGRectMake(0,0,20,100);
[self.sliderContainer2 addSubview: slider2];
}
and then I implement the method here...
- (void)controlValueDidChange:(float)value sender:(id)sender {
DCSlider *slidertag = (DCSlider *)sender;
switch (slidertag.tag)
{
case 0:
{
[PdBase sendFloat:value toReceiver:@"beatvol"];
}
break;
case 1:
{
[PdBase sendFloat:value toReceiver:@"bassvol"];
}
break;
}
}
Can anyone help please? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哎呀,还在吗?
显然您需要为每个滑块分配一个单独的目标!
另外,在您的示例中,您在创建滑块之前分配标签,这不好。您应该始终在设置任何属性之前放置
init
。如果您要使用我对您的回答其他问题,您至少可以投赞成票。 ;—]
Geez, still at it?
You obviously need to assign a separate target for each slider!
Also, in your example, you assign the tag before you create the slider, no good. You should always place your
init
before setting any properties.And if you are going to use my answer to your other question, the least you could do is give it an upvote. ;—]
您应该在此处重新检查您的 switch 语法。基本上,您应该丢失内部分隔符。
You should re-check your switch syntax here. Basically, you should lose the inner delimiters.