2014-10-01 7 views
1
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // step 1. check the device 
     var idiom = UIDevice.currentDevice().userInterfaceIdiom 

     // step 2. take a storyboard variable 
     var storyBoard:UIStoryboard? = nil 

     // step 3. load appropriate storyboard file 
     if idiom == UIUserInterfaceIdiom.Phone { 
      storyBoard = UIStoryboard(name: "Main", bundle: nil) 
     } else { 
      storyBoard = UIStoryboard(name: "Main_iPad", bundle: nil) 
     } 

     // step 4. un-box storyboard to sb variable 
     if let sb = storyBoard { 

      // step 5. create new window 
      window = UIWindow(frame: UIScreen.mainScreen().bounds) 

      // step 6. generates error :('Cannot assign to the result of this expression' 
      self.window?.rootViewController?.storyboard = sb 

      // step 7. make key window & visible 
      window?.makeKeyAndVisible() 
     } 
     return true 
    } 

6 단계에서 오류가 발생합니다! 내가 새로운 것을 빨리 배우기 때문에 여기서 코드를 작성하는 것이 어려워졌습니다.스위프트 - 프로그래밍 방식으로 스토리 보드로드

답변

5

스토리 보드는보기 컨트롤러에 대한 정보가 들어있는 XML 파일 일뿐입니다. 보기 컨트롤러 (또는 탭 막대 컨트롤러 또는 탐색 컨트롤러와 같은 다른 컨트롤러)를 인스턴스화하여 응용 프로그램 창의 루트보기 컨트롤러로 설정해야합니다.

window.rootViewController = sb.instantiateInitialViewController() as MyWhateverController 
관련 문제