Skip to content

Instantly share code, notes, and snippets.

@susieyy
Created January 14, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save susieyy/76b02bc09c3d8dcae247ac8d9df4927d to your computer and use it in GitHub Desktop.
Save susieyy/76b02bc09c3d8dcae247ac8d9df4927d to your computer and use it in GitHub Desktop.
#swtws
final class HogeViewController: UIViewContoller {
private lazy var searchViewController: SearchViewController = {
let vc = SearchViewController()
self.addChildViewController(vc)
self.view.addSubview(vc.view)
vc.view.snp_makeConstraints { $0.edges.equalToSuperview() }
vc.didMoveToParentViewController(self)
return vc
}()
}
extension HogeViewController: UISearchBarDelegate {
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
// 以下の最初の参照時に初めてsearchViewControllerが初期化される
searchViewController.search(searchText)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment