2017-02-13 7 views
0

私は1ヶ月のiOSコースを受け取り、Xcodeの変更によりコンテンツが少し古くなっていたことがわかりました。レッスン4では、最初にstoryboardとviewControllerを削除し、Info.plistの「メイン」タブを削除することで、先生がappDelegate.swiftの背景色を変更するよう教えてくれました。そして、彼は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

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

を(フレーム:UIScreen.main.bounds) 自己。 window?.backgroundColor = UIColor.magenta'、mainScreenがmainに変更された場合、あなたのケースでは、灰色、黒色、マゼンタなどのUIColorプロパティからカラーのWord(不要と見なされます)が削除されます。 –

+0

ええ、あなたが前に提案したものを正確に試しました。 \t self.window = UIWindow(フレーム:UIScreen.main.bounds)self.window?.backgroundColor = UIColor.magenta self.window?.makeKeyAndVisible()しかし、NSexceptionを取得します。Thread1:SIGABRTを実行時にしますか?他のより良い解決策がありますか?とにかく助けてくれてありがとう。 –

+0

例外をどの行で取得しましたか? –

答えて

0

私はG +から素晴らしい答え受け取った:私はちょうどrootViewControllerを初期化するのを忘れ...

関連する問題