【问题标题】:how to change the UI based on the settings of a segmented control如何根据分段控件的设置更改 UI
【发布时间】:2012-03-20 11:50:34
【问题描述】:

在一个UIViewController 中,我有一个UISegmentedControl

当我选择分段 control.selectedindex==0 时,它将显示一个文本字段。

当我选择 segmentedcontrol.selectedindex==1 时,它将显示另一个分段控件而不是文本字段。

我该怎么做?

【问题讨论】:

  • 你能说得更具体点吗?它不会让任何人了解你倾向于做什么!!!
  • @Kevin,请您重新检查您的问题描述!我在想有什么错误。我不明白。
  • Segmentedcontrol.selectedindex==0 给出文本字段,segmentedcontrol.selectedindex==1 给出另一个分段控件。
  • 发布任何截图,如果可以的话..
  • 我尝试重新表述这个问题。希望现在更清楚了。

标签: iphone cocoa-touch ios4 uisegmentedcontrol


【解决方案1】:

您不会只有 2 个分段控件,但其中一个是隐藏的。 当第一个的 selectedindex==1 时,取消隐藏第二个。

【讨论】:

    【解决方案2】:
    -(IBAction)yourSegmentControl:(id)sender{
    
    switch ((((UISegmentedControl *)sender).selectedSegmentIndex)) {
        case 0:
            {
               anothersegment.hide = YES;
               yourTextfield.hide = NO;
               break;
            }
    case 1:
           {
               anothersegment.hide = NO;
               yourTextfield.hide = YES;
               break;
            }
    
        default:
            break;
    }
    
    }
    

    确保在 viewDidLoad 中初始化文本字段和 secondsegmentcontrol
    两者都隐藏 = YES;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 2012-08-12
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多