简体   繁体   English

iOS:使用分段控件更改子视图

[英]iOS: change subview with segmented control

I have four subview and when I select (segment ==1) in segmented control other view must have alpha at 0.00 and only subview number 1 must have alpha at 1.00, I show my code: 我有四个子视图,当我在分段控件中选择(segment == 1)时,其他视图的alpha必须为0.00,只有子视图1的alpha必须为1.00,我显示了代码:

if (segmentedContr.selectedSegmentIndex == 1) {

    [subView1 setAlpha:0.0];

      }

it's simple, but where I must write this code? 很简单,但是我必须在哪里编写这段代码? In an IBAction? 在IBAction中? or in a generic method (void)? 或通用方法(无效)? If I do 如果我做

-(void)segmentAction:(id)sender

where I must call this method? 我必须在哪里调用此方法?

You don't have to call that method explicitly from anywhere. 您不必从任何地方显式调用该方法。

That method will be called automatically when you select a segment in the segmented control. 当您在分段控件中选择一个分段时,将自动调用该方法。 And, make sure you have set the target and action for the segmented control. 并且,请确保已为分段控件设置了目标操作

[segmentedContr addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM