I will suppose that you hace an NSArray
to know which color is every row in the TableView.
Then you can save the color in NSUserDefaults
instead of an Integer.
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
[[NSUserDefaults standardUserDefaults] setObject:[UIColor redColor] forKey:@"ChosenColor"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
Then, when you reopen the app you can retrieve this data in viewDidAppear:
with:
- (void) viewDidAppear:(BOOL)animated
{
UIColor *color = [[NSUserDefaults standardUserDefaults] objectForKey:@"ChosenColor"];
[yourObject setColor:color];
}
However, because you are trying to do something for the whole app. You can do it in your AppDelegate.m.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Usually your UINavigationController will be your rootViewController
UIColor *color = [[NSUserDefaults standardUserDefaults] objectForKey:@"ChosenColor"];
UINavigationController * navigationController =(UINavigationController *)self.window.rootViewController;
[navigationController.navigationBar setBarTintColor:color];
}
If you want to pick a color in one ViewController and go back to your main ViewController and set the selected color you should use a Delegate, too. If you don't know about delegation, check this links: