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 07-21-2011, 09:12 PM   #1 (permalink)
Registered Member
 
mebarron's Avatar
 
Join Date: Apr 2009
Location: Michigan
Posts: 47
mebarron is on a distinguished road
Default When an iPad app comes from background to foreground , I want to alter the barButtons

When an iPad app comes from background to foreground , I want to alter the barButtons on home view based on Preference settings.

1. Put app in background by pushing the round button
2. I Run Settings App , and set a preference for the app to YES
3. Bring app to foreground by touching the icon
4. the AppDelegate is set as an observer of a Notification in applicationDidFinishLoading using:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEnteredForeground
name:UIApplicationWillEnterForegroundNotification object:nil];

5. The viewController for the home view is rootTableViewController
6. In the handler for the EnterForegroundNotification in appDelegate.m , I call a method in the viewController

[[self rootTableViewController] doit];

6. In doit , I check the preference this way:
BOOL bImportRecipes = [[NSUserDefaults standardUserDefaults] boolForKey:@"Import_Recipes"];

and then set the BarButtons accordingly.

The problem is this usually work about half the time. It is found to be Yes about half the time.
The Notification arrives each time and is handled everytime. The problem is in reading the
Preferences for the app

What can I do?

---
I tried a work around. I move the reading of the Preference to the Notification
handler in AppDelegate. I then send the preference value to
setImportButton method of rootTableViewController as a parameter.

I also changed the Notification to:
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(handleEnteredForeground
name:UIApplicationDidBecomeActiveNotification object:nil];

I now have a predictable failure of the preference reading when handling
the on the first try and a success on
the second try. That is:

1. Put app in Background - round button
2. Set Preference to YES in Settings app
3. Bring to foreground - touch icon
4. Preference is read as NO and passed to - (void)doitBOOL)bDoImport
5. Put app in Background
6. Bring app to Foreground
7. Preference is read correctly as YES

Is this a bug?

Last edited by mebarron; 07-22-2011 at 11:59 AM.
mebarron is offline   Reply With Quote
Reply

Bookmarks

Tags
nsnotificationcenter, 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: 403
16 members and 387 guests
7twenty7, blasterbr, buggen, chiataytuday, Clouds, dre, EvilElf, HemiMG, jeroenkeij, jimmyon122, jonathandeknudt, LEARN2MAKE, n00b, nyoe, pungs, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,668
Threads: 94,121
Posts: 402,901
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jonathandeknudt
Powered by vBadvanced CMPS v3.1.0

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