Reputation: 161
In my app I'm moving from one view controller (the OptionsViewController, here forth the OVC) to another (the MainViewController, or MVC). In the OVC, I just have some sliders and switches which allow the use to set various options related to the MVC. When the MVC is loaded in, it instantiates a custom label, a ScrollingLabel
, which is essentially just a UILabel inside a UIScrollView controlled by the accelerometer within the device.
To move between from the OVC to the MVC, I just have a button with a segue connecting the two which passes the settings onto the MVC. The MVC then creates a new ScrollingLabel with the given settings, and starts the scrolling so the user may control the whole interface with the accelerometer. On the MVC, I have a reset button which segues back to the OVC and removes the ScrollingLabel
from the superview (by removing its constituent UIScrollView from the superview). In this manner, you can go back and forth between the two controllers.
All of this works perfectly, except in a rare, but reproducible instance. When I set the fontSize of the ScrollingLabel
text to a large value (say 200, which translates to about 10 characters visible perline on the screen at any given time when in landscape mode), and then toggle back and forth between the OVC and MVC by their respective segue buttons an abnormality happens. At font size 200, the fourth time I try to move from the OVC to the MVC (meaning I have already successfully segues from the OVC to the MVC and back 3 times), the screen freezes.
The screen will be stuck on the view of the OVC, and intriguingly will randomly, with no user input, spawn large black rectangles on the screen, which, randomly once again, flicker in and out of existence with an approximate frequency of 10+sec. Some more abnormalities. I added some print statements to the MVC viewDidLoad(), and yes, even on that 4th time the MVC IS BEING LOADED, but the view remains on the OVC, which is now non interactable, and develops the aforementioned black rectangles periodically.
I was confused by this, and so tested further. After that fourth time, I tilted the iPad, so that if the MVC had actually somehow been loaded behind the OVC, the text in its ScrollingLabel
would scroll along, and I could check if its content offset had changed. I decided to then quit out of the app using the home button, and reenter by clicking on the app icon. Much to my amazement, this now opened to the MVC, with the text correctly moved by my use of the accelerometer. This means that indeed the MVC was being loaded behind the OVC, and was taking in data from the accelerometer, but for some reason the OVC was remaining on the screen.
Even MORE confusingly, after doing the whole "exit with the home button, reenter via the app icon" trick the problem has not occurred again, UNTIL I rebuild from XCode, at which point the whole process resets, with the 4th OVC->MVC transition freezing up.
So now I am very confused, and really have no idea why such a development is occurring. I thought that maybe I am not correctly deallocating the ScrollingLabel
in the MVC when I reset back to the OVC, which for large enough fontSize, could be very expensive, but as I recreate the Label everytime I reenter the MVC I am not sure. Any assistance at all would be incredibly appreciated, and I am happy to provide code, or more information as needed.
tl;dr - The segue from one view controller to another leaves the original view controllers image on the screen, but still allows control of the correct view controllers elements without any visual indication this is taking place.
Upvotes: 0
Views: 157
Reputation: 131481
How are you segueing back from your OVC to your MVC?
If you're not using an unwind segue then you are stacking a new instance of the OVC on top of the previous OVC/MVC pair every time you segue back.
Log the address of the OVC in it's viewWillAppear. I bet you find you're getting a new one each time.
If you do a navigation controller push, us an IBAction with a popViewController call on it.
If you're doing a modal presentViewController:animated:completion:
, use an IBAction on your OVC's back button that calls dismissViewController:animated:Completion:
Alternately implement an unwind segue.
Upvotes: 0