본문 바로가기
IT라이프

iOS swift3로 화면 이동하기

by zairan 2016. 12. 15.

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)

반응형

'IT라이프' 카테고리의 다른 글

cocoaPods 설치  (0) 2016.11.15
CocoaPods 설치 하기  (0) 2016.11.10
PHP 리팩토링(2)  (0) 2015.06.04
PHP 리팩토링(1)  (0) 2015.06.04
Laravel 5 루트 설정  (0) 2015.05.30

댓글