Last active
December 25, 2019 07:05
-
-
Save freddi-kit/328e5c1b6bf1659b27f654efecdfb3e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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