In View #1 I have two controls that are set in the storyboard; one is a UIBarButtonItem in the nav bar, the other is a UISegmentedController. The former is a custom-drawn image, and both items have their tint set to a purple color (tint set in the storyboard attributes inspector).
Through various actions, the user can get to View #2 via View #1. If a certain condition is not met when in View #2, the user is displayed an error message, and is redirected back to View #1 upon clicking "OK".
Pertinent Code:
if(i == [self.itemsAvailable count]){
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Oh no!"
message:@"Warning message text!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alertView show];
break;
}
Note that the alert is triggered within a while
loop, hence the break;
. The following function then returns to View #1
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == [alertView cancelButtonIndex]) {
// Jump back one screen
[self.navigationController popViewControllerAnimated:YES];
}
}
The thing is, when I return to View #1 using the popViewControllerAnimated:YES
function, the two controls mentioned previously (the UIBarButtonItem and the UISegmentedController) have their tints showing as grey instead of the desired purple.
Selecting a different UISegmentedController value brings back the appropriate tint color, but I need to leave View #1 for the UIBarButtonItem to return to the proper purple tint.
How come the tint colors are changing, and how can I remedy this issue so that they automatically have the appropriate tint colors upon popping back to View #1?
Note:
View #1 has the following viewWillAppear
function
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// Unhide the nav bar (hidden on home screen)
[self.navigationController.navigationBar setHidden:NO];
[self setUserDefaults]; // Load the appropriate values and set in UISegmentedController
}
where
- (void) setUserDefaults {
// Set the defaults from the settings
int selectedValue;
selectedValue = (int)[self.userDefaults integerForKey:@"SomeValue"];
[self.defaultsSegment setSelectedSegmentIndex:selectedValue];
}
Some variable names have been modified and some code has been omitted, but this is the important parts. I do not believe that the function has anything to do with the incorrect tint color, because the UIBarButtonItem is never modified through code and is showing the same error as the UISegmentedController.
Edit #1:
Adding the line [self loadView];
to the viewWillAppear
method fixes the UISegmentedController tint color, but I cannot yet figure out how to fix the UIBarButtonItem tint problem. Using the line [self.navigationController loadView];
causes a whole mess of issues.
Edit #2:
The UIAlertView
is called within a method that itself is called from viewWillAppear
. If I move the method call to viewDidAppear
then the UIBarButtonItem
retains its proper tint color. But then the graphics within the view suddenly appear AFTER the view has finished loading - which is unsightly.