我的分段 Controller 中有 3 个分段。它们充当排序按钮,影响另一个 View Controller 中 TableView 内显示的数组的顺序。分段 Controller 和 TableView 位于不同的场景中。
这 3 个部分依次为距离、等级和 A-Z。我将选择 A-Z,当我返回表格 View 时,这将按字母顺序对它们进行排序。但是,如果我要返回带有分段 Controller 的场景,离开表格 View 所在的场景,则距离段将突出显示。尽管如此,它们仍然按 A-Z 排序。
如何保持我最初点击的片段突出显示,而不是始终是第一个片段?
最佳答案
不太确定你的问题。
但这就是保存和选择分段控件索引的方式
@IBOutlet weak var segmentControl: UISegmentedControl!
var selectedIndex = 0
// Save
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
segmentControl.selectedSegmentIndex = selectedIndex
}
// Load and Select
@IBAction func segmentControlValueChanged(sender: UISegmentedControl) {
selectedIndex = sender.selectedSegmentIndex
}
关于swift - 如何设置选择分段 Controller 中的哪个分段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37035263/