2017-02-13 84 views
0

我花了一個月的iOS課程,發現內容有點過時,因爲Xcode的變化。在第四課中,老師教我們改變appDelegate.swift中的背景色,首先刪除故事板和viewController,同時刪除Info.plist中的「main」標籤。然後,他在代碼鍵入appDelegate.swift:在Xcode 8.2.1中更改背景顏色,無故事板和viewController

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

    // Override point for customization after application launch. 

    self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
    self.window?.backgroundColor = UIColor.magentaColor() 
    self.window?.makeKeyAndVisible() 

    return true 
    } 

But the syntax is little bit different in Xcode8.2.1, so i modified it to the code as below. But it doesn't work either.

Then i found that there were updated codes on Github for this course. Unfortunately, it did't work either(but I know it's because it did not define "StaffPicksViewController"). 所以,我應該怎麼做才能改變背景顏色沒有故事板和ViewController?

+0

'self.window =的UIWindow(幀:UIScreen.main.bounds) 自我。窗口?.backgroundColor = UIColor.magenta',mainScreen更改爲main,顏色Word(被認爲不必要)從UIColor屬性中移除,例如灰色,黑色和洋紅色。 –

+0

是的,嘗試完全按照你之前的建議。我不知道它是什麼,但是我不知道它是什麼,但是我不知道它是如何工作的。有其他更好的解決方案嗎?還是要謝謝你的幫助。 –

+0

你哪一行得到異常? –

回答

0

我獲得了極大的答案,從G +:

self.window = UIWindow(frame: UIScreen.main.bounds) 
self.window?.rootViewController = UIViewController() 
self.window?.backgroundColor = UIColor.magenta 
self.window?.makeKeyAndVisible() 

我只是忘了初始化一個RootViewController的...