Skip to content

Instantly share code, notes, and snippets.

@freddi-kit
Last active December 25, 2019 07:05
Show Gist options
  • Save freddi-kit/328e5c1b6bf1659b27f654efecdfb3e9 to your computer and use it in GitHub Desktop.
Save freddi-kit/328e5c1b6bf1659b27f654efecdfb3e9 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// test
//.
//
import UIKit
class ViewController: UIViewController {
// view上にあるサブビュー
@IBOutlet weak var containerView: UIView!
let vc = ViewController2()
// view上にあるボタン
@IBAction func onButtonTapped(_ sender: Any) {
// completionはコールされるけどvcはcontainerViewから消えない
vc.dismiss(animated: true, completion: {
print("completion")
})
}
override func viewDidLoad() {
super.viewDidLoad()
// vcをchild vcとしてcontainerViewに埋め込む
addChild(vc)
vc.willMove(toParent: self)
containerView.addSubview(vc.view)
}
}
class ViewController2: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .red
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// よばれない
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment