Search code examples
iosswiftswift4xcode10

Properties assigned to UIButton in ViewController.swift and segue works on Simulator but not on Device


I have an extremely bizarre problem. I created a UIButton and put it on my ViewController storyboard. I added a segue from the Button to another ViewController by pressing control and dragging. I also added an outlet to the corresponding ViewController file and added a border color and width (to the button). The segue and the button border work fine on the simulator but on a device the button border does not show up and the segue does not work.

The only thing I can think of that could be causing the problem is that a little while ago I accidentally deleted my Main.storyboard, so I dragged it from my trash back to my Xcode project. But I am pretty sure my app has worked on the device even after that incident. I wasn't sure if my viewDidLoad method was being fired (since that is where I set my border color and width for the button) so I added a print statement and found out that it was indeed being called. Take a look at the code below...

     override func viewDidLoad() {
        super.viewDidLoad()
        print("Begin Setup Process...")
        // Do any additional setup after loading the view.
        calibrateButton.layer.borderColor = UIColor.white.cgColor
        calibrateButton.layer.borderWidth = 3
    }

How would I get this to work on my device as well? What I am doing wrong


Solution

  • I finally solved the issue. The problem was that I didn't have a height constraint on my button. I am still not exactly sure why or how this issue occurred. Why couldn I see the button text but not the border? If the segue was not working there must have been a view on top of the button that was preventing it from going off. But anyway adding a height constraint solved the problem. In answering my own question I realize that the title of my question is misleading in relation to the solution of the problem. This problem, in the end had nothing to do with wether the app was running on a simulator or the device. I just assumed it was a device issue since it was working fine on my iPhone XR simulator but not my actual iPhone 6s. However the actual problem was the screen size and how my constraints adapted to it.