Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-03-2012, 07:54 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 8
JackSac67 is on a distinguished road
Question How is viewWillAppear called?

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?
JackSac67 is offline   Reply With Quote
Old 02-03-2012, 08:55 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

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.

©2011 Dardom Productions | Like us on Facebook!
SoulRed12 is offline   Reply With Quote
Old 02-03-2012, 08:59 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Quote:
Originally Posted by JackSac67 View Post
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.
dapis is offline   Reply With Quote
Old 02-04-2012, 11:05 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 8
JackSac67 is on a distinguished road
Default

Quote:
Originally Posted by dapis View Post
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?
JackSac67 is offline   Reply With Quote
Old 02-04-2012, 11:14 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Quote:
Originally Posted by JackSac67 View Post
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.
dapis is offline   Reply With Quote
Old 02-04-2012, 11:19 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

You can override it...
Code:
- (void)viewWillAppear:(BOOL)animated {
  // Code
}
harrytheshark is offline   Reply With Quote
Old 02-04-2012, 11:21 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 8
JackSac67 is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
You can override it...
Code:
- (void)viewWillAppear:(BOOL)animated {
  // Code
}
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.
JackSac67 is offline   Reply With Quote
Old 02-04-2012, 12:57 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by JackSac67 View Post
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.)
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
load, textview, viewwillappear

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
18 members and 378 guests
Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, kukat, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0