ios - Swift - 分段控制 - 切换多个 View

标签 ios swift xcode6

直到现在我还是想不出如何在一个 View Controller 中切换多个 View 。我的 Storyboard是这样的。

enter image description here

现在我想在我的 View Controller 中嵌入两个 View 。

enter image description here

到目前为止,我的分段控制代码可以在一个 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,并使用与上述答案中建议的设置隐藏属性相同的方法。

enter image description here

关于ios - Swift - 分段控制 - 切换多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27956353/

相关文章:

ios - AVPlayerLayer 不在 iOS 11 中呈现离线 HLS 视频

ios - 设置 UIStackView 的排序顺序

ios - UITableView contentSize 未更新

xcode - 删除 Xcode 6 中的默认代码片段

xcode6 - 为什么 Xcode 6.1 在 IOS 8 模拟器中杀死了 [NSLocale preferredLanguages]

ios - tableview controller、嵌入式 tableview 或其他用于此界面的东西?

swift XCTAssertEquals 成功与可选

objective-c - 使用未声明的类型 'XXX',Xcode 7.3,swift 2.2

iOS uiautomator 应用程序名称

ios - SKAction : How to Animate Random Repeated Actions