OK, so every time I load a new view, a text view is being changed. To my understanding, that means I need to add a viewWillAppear method, which I did and the appropriate code so the text view changes on load based on user input. However I don't understand how to call this. Help?
viewWillAppear is called on a view's view controller when the view is about to appear onscreen. This means, however, it is called both when it is first appearing/covering or replacing another view, and when a view that covered/replaced it is disappearing.
__________________
HEY! Was this post helpful?
If so, it would be MUCH appreciated if you'd just click on one of these apps:
MyD
Take 1 minute to set up your MyD and you'll always be able to prove you own your device!
Membrik
Test your memory by sliding tiles to match chains of increasing difficulty.
OK, so every time I load a new view, a text view is being changed. To my understanding, that means I need to add a viewWillAppear method, which I did and the appropriate code so the text view changes on load based on user input. However I don't understand how to call this. Help?
You don't call viewWillAppear, it is called by the OS when -- pause for effect -- the view will appear.
You don't call viewWillAppear, it is called by the OS when -- pause for effect -- the view will appear.
So if you can't override it manually, how can I change a certain property every time the view appears? viewDidLoad only works the first time the view is loaded, but in my second view, there's a text view that changes based on user input from the first view. So, how can I update that text view every time the second view loads?
So if you can't override it manually, how can I change a certain property every time the view appears? viewDidLoad only works the first time the view is loaded, but in my second view, there's a text view that changes based on user input from the first view. So, how can I update that text view every time the second view loads?
viewWillAppear is not the same as viewDidLoad. viewWillAppear gets called every time the view appears - so simply put a call to the code you want to execute inside the viewWillAppear code for the relevant view, and all will be well.
Yeah, see that's what I thought. I looked up the documentation and found that, but when I put the code in it wasn't working... so the issue is my code xD I'll see if I can fix that.
Yeah, see that's what I thought. I looked up the documentation and found that, but when I put the code in it wasn't working... so the issue is my code xD I'll see if I can fix that.
Make sure you got the method declaration exactly correct. If you change the spelling or upper/lower case, or don't have the correct number of parameters (1, in this case) it is considered a different method, and won't get called. I usually copy and paste method declarations from the docs (or working code) for this reason.
Also, try adding log statements to the beginning of both your viewDidLoad method and your viewWillAppear: method. This log statement works really well:
Code:
NSLog(@"Entering method %s", __PRETTY_FUNCTION);
(With a nod to Brian Slick, from whom I learned about the __PRETTY_FUNCTION compiler macro.)
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.