【问题标题】:Segmented controls affect button分段控件影响按钮
【发布时间】:2013-10-07 02:31:36
【问题描述】:

我需要设置我的分段控件以影响我的按钮将用户发送到何处。 Yes 将它们发送到新屏幕,No 将它们发送到下一个屏幕。

第一段:

UISegmentedControl *par;

Yes (0) 在点击下一个按钮时将用户发送到 UIViewController ParError。 否(1 - 默认)在单击下一步按钮时将用户发送到 UIViewController 条款UI。

第二段:

UISegmentedControl *basicOp;

是 (0) 在单击下一个按钮时将用户发送到不支持的 UIViewController。 否(1 - 默认)在单击下一个按钮时将用户发送到 UIViewController 条款UI。

我已经尝试过 If 语句,但它变得很复杂,当两者都被选中时,我不断收到错误消息。有人想要工作吗?我无法通过任何开发人员指南弄清楚。请帮忙?

我是 Xcode 和 Objective-C 的新手,所以请解释一下操作步骤。

注意:我不需要将其作为子视图。它所做的是将用户推送到另一个屏幕,女巫给出了关于做什么的新指令,然后将它们带到与原始屏幕不同的另一个屏幕。

【问题讨论】:

  • 当您同时在Yes(0) 上拥有par segmentbasicOp segmentYes(0) 上时会发生什么?
  • 我需要它才能进入不受支持的屏幕,因为即使 par 是 no,basicOp 也会将您带到一个屏幕,说这是不受支持的。

标签: ios objective-c uiviewcontroller ios7 xcode5


【解决方案1】:

要获取您的 SegmentControls 的当前值,请使用属性.selectedSegmentIndex。这将返回在您的 segmentControl (More information about UISegmentedControl class reference) 中选择的选项的索引,

据我了解,par 段只有两个元素:YESNO。在那个特定的顺序上,

if (par.selectedSegmentIndex == 0) {
    // YES is selected, perform the action for going to ParError UIViewController
} else {
    // NO is selected, perform the action for going to TermsUI UIViewController
}

如果basicOp在同一订单上也有两个选项:YESNO

if (basicOp.selectedSegmentIndex == 0) {
    // YES is selected, perform the action for going to Unsupported UIViewController
} else {
    // NO is selected, perform the action for going to TermsUI UIViewController
}

假设您要实现以下目标:

  • 如果par 为YES(无论basicOp 是什么值),应用程序将用户发送到ParError UIViewController
  • 如果par 为NO,basicOp 为YES,应用程序将用户发送至Unsupported UIViewController
  • 如果 par 为 NO 且 basicOp 为 on ,则应用将用户发送至 TermsUI UIViewController

你应该有的条件是:

if (par.selectedSegmentIndex == 0) {
    // YES is selected, perform the action for going to ParError UIViewController
} else if (basicOp.selectedSegmentIndex == 0) {
    // YES is selected, perform the action for going to Unsupported UIViewController
} else if (par.selectedSegmentIndex == 1 || basicOp.selectedSegmentIndex == 1) {
    // NO is selected, perform the action for going to TermsUI UIViewController
}

【讨论】:

  • 我想我知道我自己的 if/else 语句出了什么问题,但是我会调用什么操作来让用户在按钮按下时转到另一个屏幕?
  • 您使用的是 NavigationViewController 吗?然后,[self.navigationController pushViewController:yourViewController animated:YES];
  • 应用程序正在做的是向用户询问两个问题,如果用户对第一个问题(par)说是,则单击下一步时会将他们带到一个屏幕。如果他们对第二个(basicOp)说“是”,那么它会将他们带到第二个屏幕。第二个需要覆盖第一个,因为第二个会将它们带到不受支持的屏幕。
  • 那么可能是一个模态,[self presentViewController:yourViewController animated:YES completion:nil];
  • 重读我的上一条评论,因为我没有代表点来发布图片,所以不得不更改它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多