要获取从 SegmentControls 中选择的当前值,请使用属性.selectedSegmentIndex
。这将返回在您的 segmentControl 中选择的选项的索引(有关 UISegmentedControl 类参考的更多信息),
正如我从您的问题中了解到的那样,par
段只有两个元素:YES
, NO
. 在那个特定的顺序上,
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
在同一订单上也有两个选项的情况下: YES
,NO
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
}