IOS/예제모음
swift 화면 이동
행복한 수지아빠
2017. 4. 18. 11:42
반응형
storyboard 를 사용해서 간단하게 화면이동이 가능하지만, 조건문과 함께 사용할때는 코드로 이동하는 것이 편할때가 있다.
같은 스토리보드내에 있는 다른 뷰로 이동하는 경우
// nextViewController.swift 인 경우
let storyboard: UIStoryboard = self.storyboard!
let nextView = storyboard.instantiateViewController(withIdentifier: "nextViewController")
self.present(nextView, animated: true, completion: nil)
현재와 다른 스토리보드에 있는 뷰로 이동하는 경우
xcode 상에서 is Initial View Controller 에 체크를 해도 되지만,
아래와 같이 name 파라미터에 스토리보드의 이름을 넣어도 된다.
// 파일명이 Next.storyboard 인 경우
let storyboard: UIStoryboard = UIStoryboard(name: "Next", bundle: nil)
let nextView = storyboard.instantiateInitialViewController()
self.present(nextView!, animated: true, completion: nil)
출처: http://geguri.tistory.com/45 [개구리의 IT공간]
출처: http://geguri.tistory.com/45 [개구리의 IT공간]
반응형