1

I try add child view controller multiple. i want to add search controller to home controller as child view controller . that's work good hear is my code :

func ShowSearchController() {

    let secondViewController:SearchController = SearchController()
    let navController = UINavigationController.init(rootViewController: secondViewController)
    self.navigationController?.addChildViewController(navController)

    secondViewController.navigationController?.view.frame = (self.navigationController?.view.frame)!
    secondViewController.view.frame = (self.navigationController?.view.frame)!
    self.navigationController?.view.addSubview(secondViewController.view)
    secondViewController.beginAppearanceTransition(true, animated: true)

    UIView.animate(withDuration: 0.2, animations: {
    }, completion: {
      (value: Bool) in
      secondViewController.endAppearanceTransition()
      secondViewController.didMove(toParentViewController: self)
    })

  }

now i want to show another view controller to search controller. for present second view controller i'm using this method but thats not work. how can add child view controller to navigation controller few times?

Arasuvel
  • 2,971
  • 1
  • 25
  • 40
ava
  • 1,148
  • 5
  • 15
  • 44
  • what u really want? can u explain – Midhun K Mohan Aug 14 '17 at 07:45
  • @MidhunKMohan i show search controller with add child to home controller, now i want to show another controller on search controller. but add child view controller not working. – ava Aug 14 '17 at 07:49
  • while a button click you want to show another view controller with navigationbar right? – Midhun K Mohan Aug 14 '17 at 07:53
  • yes, but thats not work, i try use navigation controller push method but this is not work. – ava Aug 14 '17 at 07:56
  • try push method `let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "your identifier") as! secondVc self.navigationController?.pushViewController(vc, animated: true)` – Midhun K Mohan Aug 14 '17 at 08:02
  • @MidhunKMohan i'm using xib file , but i try use this method thats not working.self.navigationController?.pushViewController(secondViewController, animated: true) – ava Aug 14 '17 at 08:31
  • @MidhunKMohan present modally work fine self.present(navController, animated: true, completion: nil), but when i try back to search controller from search result i got this error : Terminating app due to uncaught exception 'CALayerInvalid', reason: 'layer is a part of cycle in its layer tree' – ava Aug 14 '17 at 08:35

0 Answers0