2016-07-07 12 views
0

3つの子ビューを持つコントローラを作成しようとしていますが、これはセグメント化されたコントロールで切り替えることができます。問題は、3つのコントローラのうち2つのコンテンツの代わりに、白い画面が表示されることです。子ビューが親ビューに表示されない

コードは、ここに以下の

@IBAction func segmentedControllSelected(sender: UISegmentedControl) { 

    switch sender.selectedSegmentIndex 
    { 
    case 0: 

     self.parentView.addSubview(subViewOne!) 
     subViewOne?.frame = subViewOne!.superview!.bounds 
     subViewOne?.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 

     subViewTwo?.removeFromSuperview() 
     subViewThree?.removeFromSuperview() 
    case 1: 

     self.parentView.addSubview(subViewTwo!) 
     subViewTwo?.frame = subViewTwo!.superview!.bounds 
     subViewTwo?.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 

     subViewOne?.removeFromSuperview() 
     subViewThree?.removeFromSuperview() 
    case 2: 

     self.parentView.addSubview(subViewThree!) 
     subViewThree?.frame = subViewThree!.superview!.bounds 
     subViewThree?.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 
     print("parentView frame is \(parentView.frame.height)") 
     print("scrollView contentSize is \(scrollView.contentSize.height)") 
     print("subViewThree frame is \(subViewThree?.frame.height)") 
     subViewThree?.frame.size.height = 2000 
     print("subViewThree frame is \(subViewThree?.frame.height)") 

     subViewOne?.removeFromSuperview() 
     subViewTwo?.removeFromSuperview() 

    default: 
     break; 
    } 

} 
override func viewDidLoad() { 
    super.viewDidLoad() 

    segmentedControllPositionY = segmentedControll.frame.origin.y 
    scrollView.delegate = self 

    gameInfoMainViewController = UIStoryboard(name: "GameInfo", bundle: nil).instantiateViewControllerWithIdentifier("GameInfoMainViewController") as? GameInfoMainViewController 
    gameInfoMembersViewController = UIStoryboard(name: "GameInfo", bundle: nil).instantiateViewControllerWithIdentifier("GameInfoMembersViewController") as? GameInfoMembersViewController 
    gameInfoTeamsViewController = UIStoryboard(name: "GameInfo", bundle: nil).instantiateViewControllerWithIdentifier("GameInfoTeamsViewController") as? GameInfoTeamsViewController 
    gameInfoTeamsViewController!.delegate = self 

    self.addChildViewController(gameInfoMainViewController!) 
    self.addChildViewController(gameInfoMembersViewController!) 
    self.addChildViewController(gameInfoTeamsViewController!) 

    subViewOne = gameInfoMainViewController!.view 
    subViewTwo = gameInfoMembersViewController!.view 
    subViewThree = gameInfoTeamsViewController!.view 

} 

override func viewWillAppear(animated: Bool) { 

    self.parentView.addSubview(subViewOne!) 
    subViewOne!.frame = subViewOne!.superview!.bounds 

func scrollViewDidScroll(scrollView: UIScrollView) { 

    if scrollView.contentOffset.y > segmentedControllPositionY! - 40 { 
     segmentedControllTopConstraint.constant = scrollView.contentOffset.y + 40 
    } else { 
     segmentedControllTopConstraint.constant = segmentedControllPositionY! 

    } 

} 

func passHeight(height:CGFloat) { // delegate method which is called in controller with tableview and passes height of tableview 
    tableViewHeight = height 
    parentView.frame.size.height = tableViewHeight! 
    parentView.layoutIfNeeded() 
    scrollView.contentSize.height = tableViewHeight! + segmentedControll!.frame.height + headerView.frame.size.height 
} 

ある子ビューコントローラは、ここで

enter image description here

に見える、それはシミュレータ(白い画面、ラベルなし)でどのように見えるかある方法です

enter image description here

私は、これはいくつかの助けを提供し、この

enter image description here

+0

parentViewとは何ですか?それは画面上に正しく配置されていますか?なぜ子ビューコントローラを使用しないのですか? https://guides.codepath.com/ios/Adding-and-Removing-Child-View-Controllers – tbilopavlovic

答えて

1

希望で終わる

subViewTwo?.frame = subViewTwo!.superview!.bounds 
subViewTwo?.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 

を削除した場合、私はこれ、コンテナビュー&があなたの切り替えビューでそれを埋めるために使用する方が簡単だと思いますアクティブビューを設定することによって行われます。非アクティブビューを削除します。&他のビューを表示するコンテナビューフレーム

使用するUIを次に示します。ユーザーがセグメントビューからアイテムを選択すると、アクティブビューを変更して別のビューをロードする必要があります。 enter image description here

+0

素晴らしいよ!どうもありがとう! –

関連する問題