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 10-15-2010, 11:06 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 139
sumosumo84 is on a distinguished road
Default reading/writing logical error

Hello, i am having a reading/writing logical error.

The whole reading and writing works fine, but it doesnt read until the value changes.


1)I have the variable exp

2)exp increments by 1 everytime a picture hits the wall.

3)application quits, and exp is saved

4)application launches and exp is loaded but not displayed yet

5)the picture hits the wall and exp incriments

6)after step 5 happens exp is incrimenting after the saved value and the label matches exp's value

My problem is that if the user goes strait to the stats screen exp will be at 0, so they will be worried.

I have tried calling the load statement in viewDidLoad, awakeFromNib, and applicationDidBecomeActice; which is in the Delegate.

If you need more info please ask,

REMEMBER: the reading and writing works, it just doest read until exp changes!
sumosumo84 is offline   Reply With Quote
Old 10-16-2010, 12:37 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

I assume you have a label set up in interface builder, and hooked up to an outlet in your view controller.

I suspect you're trying to set myLabel.text = blah before the view is actually loaded, and therefore before myLabel is still set to nil. Any message sent to nil is ignored, so calling nil.text = blah does nothing. Try debugging or logging myLabe to see if it is nil.

This happens because views are not actually loaded until someone asks for myController.view - that's when the view is built and the outlets are connected.

I typically load the data when the app starts, pass the data into a property of the view controller, and then set the labels / fields in viewWillAppear. I'd love to hear what others do, though.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 10-16-2010, 12:52 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 139
sumosumo84 is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
I assume you have a label set up in interface builder, and hooked up to an outlet in your view controller.

I suspect you're trying to set myLabel.text = blah before the view is actually loaded, and therefore before myLabel is still set to nil. Any message sent to nil is ignored, so calling nil.text = blah does nothing. Try debugging or logging myLabe to see if it is nil.

This happens because views are not actually loaded until someone asks for myController.view - that's when the view is built and the outlets are connected.

I typically load the data when the app starts, pass the data into a property of the view controller, and then set the labels / fields in viewWillAppear. I'd love to hear what others do, though.
ok. thanks, i have this app more than halfway built, and i wouldnt want to transfer my labels into a viewWillAppear, unless its not that hard of course.

Is there a function to set exp to [[NSUserDefaults standardDefaults] integerWithKey:@"key"]; before the view loads, like a beforeViewLoads method?
sumosumo84 is offline   Reply With Quote
Old 10-16-2010, 01:23 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 139
sumosumo84 is on a distinguished road
Default

nvm about my last post, i figured out what you meant, and thanks! it works great!!!
sumosumo84 is offline   Reply With Quote
Old 10-16-2010, 10:01 AM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

No problem, I should have been more clear. This is better: "The view (and outlet objects) are not loaded yet when viewDidLoad, awakeFromNib, and applicationDidBecomeActive are called. You can't set the text of a label until viewWillAppear or viewDidAppear."
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
code, error, logical, reading files, writing files

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: 340
8 members and 332 guests
Desert Diva, dre, hain, HemiMG, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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