ios개발/프로젝트

<watchOS> WKInterfaceController : watchOs에서는 뷰컨트롤러 대신 컨트롤러가 있다....?

studying develop 2020. 10. 13. 23:17

 

와치 개발중에 스토리 보드를 이용하는데, 기존과 다르게 뷰컨트롤러 관련 클래스랑 메소드들이 없어서, 찾아보니 워치는 다른걸 사용한다.

WKInterfaceController

An interface controller serves the same purpose as a UIViewController object in a UIKit app, except that it does not manage any actual views. It runs in your WatchKit extension and remotely manages the behavior associated with an interface controller in your Watch app’s storyboard file. You subclass WKInterfaceController and use its methods to configure the elements of your storyboard scene and to respond to interactions with those elements.

 

요약하면 UIViewController랑 같은 기능을 한다. ㅎㅎ

 

일단 그래 뭘 기존 뷰컨트롤러처럼 사용해야 하는지는 알았고, 그럼 어떻게 해당 컨트롤러를 푸쉬할지 찾아봤더니.

 


 

push를 하면된다는데, withName이 스토리보드안에 만든 컨트롤러의 identifier를 설정하면 되는거였을텐데. 이부분이 안되더라.

 

그래서 처음 생각한건 루트 컨트롤러 위에 또는 최상단 컨트롤러 웨에 푸쉬하면 된다 생각했는데, 위의 pushController에서 withName에 설정한 컨트롤러를 도저히 못찾더라....

 

 

방법을 찾는중인데. 내가 찾은건 이런 방법인데

 

guard let interface = WKExtension.shared().rootInterfaceController as? InterfaceController else {
    return
}

 

[stackoverflow.com/questions/27097022/launch-watch-app-into-middle-view] - 근데 이건 중간 부터 컨트롤러를 새로 어떻게 띄우냐는거고

 

[stackoverflow.com/questions/29894635/how-to-set-starting-page-in-watchkit-pagecontroller] - 이건 시작 컨트롤러 설정을 어떻게 하냐는거고... 

 


 

근데 보니까 이런 방법이 공식 문서로 있는데 [developer.apple.com/documentation/watchkit/storyboard_elements/building_watchos_app_interfaces_using_the_storyboard/navigating_between_scenes]

 

이럴려면 첨부터 스토리보드들이 필요했을거 같다. 스토리보드를 사용하는게 맞는건가??