简体   繁体   中英

My app gets stuck on a white screen that says copyright stuff when i run it in a ios simulator

this is my first time doing ios project and everytime i try to run this app , its stuck on the white screen . Any ideas or solutions to this problem would be appreciated . I have no idea whether its the code's fault or the simulator.

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var mySwitch: UISwitch!
    @IBOutlet var Answer: UILabel!
    @IBOutlet var tempInput: UITextField!

    //aqnswer value

    @IBAction func switchPressed(sender: AnyObject)
    {
        if ( mySwitch.on ) {
            self.Answer.text = "cel to fah"
        }
        else
        {
            self.Answer.text = "fah to cel"
        }
    }
        //textfield value

    @IBAction func calculate(sender: AnyObject)
            {
                //get user input 
                // value = celcius

                var Value:Int = tempInput.text.toInt()!
                var toFah :Int = ( 32 + Value * 9 ) / 5

                //to celcius

                var toCel: Int = (Value-32) * 5 / 9

                if (mySwitch.on)
                {
                    self.Answer.text = toFah.description
                }
                else {
                    self.Answer.text = toCel.description
                }

               // println(fah)
               // Answer.text = fah.description
                }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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

Ok, there could be a number of things that are wrong here.

1) If you are using storyboard to design the UI. Check if Viewcontroller has been set as the initial viewcontroller. You should see an arrow thats pointing at the first view controller.

2) Put in some print messages in viewDidLoad, viewWillAppear and viewDidAppear functions. This should tell you if the view controller is getting loaded.

3) Another common mistake : And this probably is what is happening. I see you have a button, right click on the button in the storyboard and see what all methods/outlets it is connected to. Some times, when you make a connection from storyboard to code. Using Control + Drag. And if you later delete the code. Storyboard still retains the link to the code. At launch it tries to connect to the code and if it doesnt find the outlet or IBaction it causes a crash.

Terrible controller naming aside, it seems like your storyboard has no entry scene (and your controller is probably not referenced there, if you create one). Xcode should give you a warning on the first problem, though.

That white screen is the default launch screen; it will go away as soon as the root view controller gets installed by the storyboard (asuming you use that).

  1. In Interface Builder, are you sure that ViewController is the class associated with the starting controller ?

  2. Can we have a screenshot of the ViewController in Interface Builder? (because from the problem explanation i understand you set up a view in Interface Builder with a text field, a button and a switch button

  3. I believe 99% of the time this is the code's fault...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM