0

I'm just starting out with iOS development and have what I think is a pretty simple question. My storyboard currently has just two screens. I need to be able to segue back and forth between these two. I have a button on each screen that references the other (i.g. screen 1 has a button that says 'screen 2' and vice versa).

I've defined segues from each button to the opposite screen. To do this, I control-dragged from the button to the opposite screen and assigned a style of 'Modal'. When I run the app and click on either of these buttons, the segue to the opposite screen occurs, but the background color of the screen is all wrong. For example, my app launches on screen 1 and it has a gray background and all looks great. Then I click on 'screen 2' and screen 2 comes up, but with a black background (it should be gray). Then I click on 'screen 1' and screen 1 comes back but this time with a red background.

Clearly I'm not understanding how to effect these segues correctly. Can somebody please tell me what I have done wrong?

Thank you!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
AndroidDev
  • 20,466
  • 42
  • 148
  • 239

2 Answers2

0

Recommendation

In a previous question (SO LINK) I have described the basic paradigm for performing a segue between view controllers. Apple has the best tutorial (LINK) that will walk you through adding a segue to move forward and unwinding a segue to move backwards. I think you will want to start with the Apple tutorial as there are a number of different ways to manage the segue. After going through the tutorials you may want to post a follow-up question.

Community
  • 1
  • 1
Tommie C.
  • 12,895
  • 5
  • 82
  • 100
0

First. You don't add a segue back from a Modal UIViewController. Just add this to the function you want to switch back to the main UIViewController from :

[self dismissViewControllerAnimated:YES completion:nil];

As for the backgrounds, you'll have to set each UIViewController's background colour individually, either through Interface Builder or through code.

Sam Fischer
  • 1,442
  • 19
  • 35