直到现在我还是想不出如何在一个 View Controller 中切换多个 View 。我的 Storyboard是这样的。
现在我想在我的 View Controller 中嵌入两个 View 。
到目前为止,我的分段控制代码可以在一个 View Controller 中切换两个 View 。
import UIKit
class PopularHistoryViewController: UIViewController {
@IBOutlet weak var segmentedControl: UISegmentedControl!
@IBAction func indexChanged(sender: UISegmentedControl) {
switch segmentedControl.selectedSegmentIndex
{
case 0:
NSLog("Popular selected")
//show popular view
case 1:
NSLog("History selected")
//show history view
default:
break;
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
另一件事,如果我在我的 Controller 中放置两个 View ,区分它的最佳做法是什么?
最佳答案
如果您想在 Xcode 中为两个重叠的 subview 进行 UI 布局,更好的解决方案是使用两个 UIContainerViewController,并使用与上述答案中建议的设置隐藏属性相同的方法。
关于ios - Swift - 分段控制 - 切换多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27956353/