ViewController 위에 ViewController 올리기.
13 Oct 2018 | swift code conventionViewController 중첩하여 올리기
-
뷰를 올리기
-
뷰 dismiss시 처리하기
- 전체 코드
/// ViewController위에 또 다른 ViewController 올리기
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let entryVc = storyboard.instantiateViewController(withIdentifier: storyNewEntry) as! MakeNewEntryViewController
add(entryVc)
entryVc.dismissHandler = {
self.collectionView.reloadData()
entryVc.remove()
}
필요한 Extension은 다음과 같습니다.
extension UIViewController {
func add(_ childVC: UIViewController) {
addChild(childVC)
self.view.addSubview(childVC.view)
childVC.didMove(toParent: self)
}
func remove() {
guard self.parent != nil else {
return
}
willMove(toParent: nil)
removeFromParent()
self.view.removeFromSuperview()
}
}
Comments