Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift Improving Our User Interface Adding a Pop of Color

Martina Vonkomerova
Martina Vonkomerova
7,790 Points

App is not showing the right screen

I tried to run the app in iOS simulator and simply didn't display colorful screen as we programmed. Has anyone a clue ?

15 Answers

Martina Vonkomerova
Martina Vonkomerova
7,790 Points
//
//  ViewController.swift
//  FirsApp
//
//  Created by Bruno on 03/07/15.
//  Copyright (c) 2015 Bruno. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var funfactLabel: UILabel!
       let funfact = FactBook()
    let colorWheel = ColorWheel()

    @IBOutlet weak var funfacButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        funfactLabel.text = funfact.factsArray[0]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showFunFact() {
        var color = colorWheel.randomColor()
        view.backgroundColor = color
        funfacButton.tintColor = color
        funfactLabel.text = funfact.randomFact()
    }


}
Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Can you post the code in the file that includes all the colors?

Martina Vonkomerova
Martina Vonkomerova
7,790 Points
//
//  ColorWheel.swift
//  FirsApp
//
//  Created by Bruno on 08/07/15.
//  Copyright (c) 2015 Bruno. All rights reserved.
//

import Foundation
import UIKit

struct ColorWheel{

    let colorsArray = [
        UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), //teal color
        UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), //yellow color
        UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), //red color
        UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), //orange color
        UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), //dark color
        UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), //purple color
        UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), //green color
    ]

    func randomColor() -> UIColor{
        var randomNumber = Int(arc4random_uniform(UInt32 (colorsArray.count)))
        return colorsArray[randomNumber]


    }

}

    ```
Martina Vonkomerova
Martina Vonkomerova
7,790 Points

I sincerely don't know why it keep showing me the blank screen with the app name.

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

For a start you should fix this line:

funfacButton.tintColor = color

I think it's supposed to be funfactButton, not funfacButton ( it's the t in fact).

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Can you post a screen shot? It would have to be a link to a photo on a different site as the markdown does not work.

Martina Vonkomerova
Martina Vonkomerova
7,790 Points

It shows a white screen with the app name

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

So, it goes to the loading screen, but it never actually gets to the fun facts. Is that right?

Martina Vonkomerova
Martina Vonkomerova
7,790 Points

Yes. And it is showing me the following error: 2015-07-09 23:06:10.390 FirsApp[1762:52801] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FirsApp.ViewController 0x7fe5f147d890> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key funfact.'

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Do you need to import the ColorWheel and FactBook files? I'm not on a mac now so I can't double check.

Martina Vonkomerova
Martina Vonkomerova
7,790 Points

I need that files since they were created during the lectures.