I have completed the entire Bull’s Eye app tutorial and the app works perfectly in the simulator but on my physical device (an iPhone7 Plus) when the app loads all I get is a black screen. I’m lost. Any help would be appreciated.
If you can upload your project as a ZIP file somewhere and provide a link here, I can take a look to see what might be going on.
I tested the BullsEye app on an iPhone 5, so it will work on older devices. However, I did get a warning that said the BullsEye target did not match the version of iOS on the phone, so I changed the “Deployment Target”, which can be found on the General tab in the build settings, from 11.2 to iOS 10.3, which is the version on the phone.
I see what you are seeing: your app works on the Simulator, but I get a black screen on my device. I was able to get your app to work on my device by changing the background color of your container View that you use to organize the buttons. I then changed the background color right back to “Clear Color”, and your app worked. I have tried cleaning your project, but I can’t find an explanation for why changing the background color makes the app work.
I played around with the background color some more, and sometimes your app will work on my device when the background color is “Default” and not when the background color is “Clear Color”, but if I keep switching the colors then “Default” stops working and “Clear Color” works. I also noted that in your app, the color does not have “Clear Color” written next to the color swatch.
Interesting - at my end, I see the black screen on simulator. I didn’t even have to launch on device (and have not tested on device yet). It appears that the project as is (with no modifications) does not load the main view controller for some reason … I need to do some checking to see what is going on but also have some other stuff going on today in the morning. So might not be till afternoon before I can take a look. Just wanted to update what I was seeing till then.
Somehow you connected the view
outlet to a Button (the view
variable is inherited from the UIViewController class which is the parent class of our ViewController class) . By default, the view
outlet is connected to that big rectangle that resembles the shape of an iPhone in the storyboard.
If you open the Connections Inspector for the ViewController, you can see that the view
outlet lists both “Button” and “View” as connections. If you hover over “Button” in the Connections Inspector, then look at the storyboard, the actual button will be highlighted, and in this case it’s the start over Button. Deleting the connection to the start over Button fixed the issue for me.
I wonder why Xcode lists both the start over Button and the View as the connections for the view
outlet? The type of the view
outlet is UIView!, so the view
variable can only be assigned one component; the view
variable can’t be assigned both the View and a Button. Because of that, I would expect that deleting the Button connection for the view
outlet would leave the view
outlet unconnected. However, Xcode seems to automatically reassign the View component to the view
variable. In fact, you can’t even delete the View connection. Xcode seems to be enforcing a rule that a ViewController can control something smaller than the whole View, i.e. a subset of the components, e.g. a Button, but the ViewController cannot control nothing.
It’s also interesting that some Simulators (carlpenn’s and mine) were able to essentially say, “This button assigned to the view outlet is a mistake, I’m going to ignore the Button and summon the View component instead.” It seems reasonable to me that an initial view controller cannot be a Button, but apparently my device could not make that determination. Maybe that’s because my device is running iOS 10.3, while my simulator is running iOS 11.2, and iOS 11.2 is smarter?
It could be that - or it could be that one of the connections out of the multiple ones were being selected at random and you two happened to hit the right combination while I did not I can’t really tell since I have no idea of the inner workings of how outlets are sorted out by core iOS when loading a storyboard …
Either way, I’m glad that mystery is solved
Maybe the View and the Button are both being assigned to the view
variable, and depending on which one of the View or Button loads last it ends up being the value of the view
variable? As far as I can tell, a connection just tells Xcode to assign the component to the variable after the component loads.
You should be aware that Xcode puts your name at the top of any file it generates, so if you want to protect your privacy, you need to delete your name from the top of every file before posting your code somewhere.
@fahim, Has Xcode provided an easy way yet to prevent your name from being on every file?
Thank you everyone, that fixed the problem! The tutorials are excellent and that the author and others are willing to help is a big bonus.
This topic was automatically closed after 166 days. New replies are no longer allowed.