Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mraheel

macrumors regular
Original poster
Apr 18, 2009
136
0
Hi,

I'm trying to ascertain the best possible way to have a very functional "settings" controller.

Is there something like "Global Variables"? Something that can be accessed from all ViewControllers.

Some setting values are BOOLs or Integers.. I can only think of is NSUserDefaults. easy to retrieve and/or set.

But, For example, a user goes unto the settings tab, which is within my app, and changes a BOOL from YES to NO. and the user comes back to the main view controller.
And if that BOOL is used in cellForRowAtIndexPath, i'd hav to reload the table to take effects UNLESS we say that app takes effect only after restart, which isnt good.
Would I hav to access NSUserDefaults in CellForRowAtIndex? to make the change? Any better alternatives?
 
Have you tried this?

Code:
-(void)viewWillAppear:(BOOL)animated{
}

This executes something when the view is going to appear. You also may try:

Code:
#import "myClass.h"

-(void)changeSomething{
id controller = [[myClass alloc] init];
[controller executeAnAction];
}

NOTE: I didn't try running this to make sure I wrote everything right.

Let me know if it works.
 
THat will probably work, I guess i'd still hav to used a variable in any case.
 
If you want to set a variable from other view controller, try this:

Code:
#import "myFile.h"

-(IBAction)yourAction:(id)sender{
id controller = [[myFile alloc]init];
[controller setValue:@"MyValue" forKey:@"MyVariable"];
[controller release], controller = nil;
}

NOTE: For example you may use setInteger instead of setValue.
 
If you want to set a variable from other view controller, try this:

Code:
#import "myFile.h"

-(IBAction)yourAction:(id)sender{
id controller = [[myFile alloc]init];
[controller setValue:@"MyValue" forKey:@"MyVariable"];
[controller release], controller = nil;
}
Seems awfully temporary. You instantiate an object, assign a value, and then release the object.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.