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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 01-01-2010, 04:50 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Exclamation NSUser Defaults problem

Hi, I'm using NSUser Defaults to set an image in a UIImageView,
this works fine and I use the following code:

myString = [[NSString alloc] initWithFormat:@"Background 2.png"];
myBackground.image = [UIImage imageNamed:myString];

NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
[stringDefault setObject:myString forKey:@"stringKey"];

But the problem I'm having is calling the string when the view loads,
I use the following code:

[myBackground.image = [[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey"]];

but I get the following errors:
expected ":" before "]" token
confused by earlier errors bailing out

I've tried everything

oooh, help please?
Vladdmeir is offline   Reply With Quote
Old 01-01-2010, 04:55 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

Get rid of the brackets at the beginning of the statement, and one of them at the end.

Tom
harrytheshark is offline   Reply With Quote
Old 01-01-2010, 05:07 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Default

Quote:
Originally Posted by harrytheshark View Post
Get rid of the brackets at the beginning of the statement, and one of them at the end.

Tom
Thanks, but now I get an EXC_BAD_ACCESS now, and if I remove that line, there are no problems...

any more ideas?
Vladdmeir is offline   Reply With Quote
Old 01-01-2010, 05:12 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

Probably because you can't set a UIImageView image with a string.
Try using:
Code:
myBackground.image = [UIImage imageNamed:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey"]];
Tom
harrytheshark is offline   Reply With Quote
Old 01-01-2010, 05:18 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Default

Quote:
Originally Posted by harrytheshark View Post
Probably because you can't set a UIImageView image with a string.
Try using:
Code:
myBackground.image = [UIImage imageNamed:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey"]];
Tom

YES! Thank you so much! You're made of awesome!
Vladdmeir is offline   Reply With Quote
Reply

Bookmarks

Tags
defaults, nsuser, nsuserdefaults

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: 254
16 members and 238 guests
2WeeksToGo, ADY, BrianSlick, dacapo, Dani77, Dattee, Duncan C, headkaze, jemicha, kapps11, mer10, mgon987, sneaky, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,743
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

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