I'm trying to test some ideas on a Tabbed Application preset - what I want to do is have the main view 90% container for subsequent views (which is working fine so far) and have a persistent status bar at the top showing a UILabel that can be updated from the subsequent views, however am having trouble updating the label.
In seeking a solution I have attempted both a global variable and protocol approach.
Whilst I can set the label text to be that of the global variable when the main view is loaded, I cannot figure out how to refresh the label once the global variable has been changed in a subsequent view. Similarly with the protocol approach, trying to create a global function in the main view that will update the instance UILabel's properties when called from a subsequent view is not allowed.
If someone could point me in the right direction I would be very grateful.
EDIT
I have tried creating a public function that can be called from subsequent views:
GlobalContainerViewController.h
@interface GlobalContainerViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
+ (void) updateLabel;
@end
GlobalContainerViewController.m
...
+ (void) updateLabel
{
_statusLabel.text = [NSString stringWithFormat:@"updated"];
}
However get the error "Instance variable '_statusLabel' accessed in class method.
I have also tried using a global variable to store the status text:
AppDelegate.h
NSString * statusVar;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
statusVar = [NSString stringWithFormat:@"initialStatus"];
return YES;
}
GlobalContainerViewController.m (with AppDelegate.h imported into .h)
- (void)viewDidLoad
{
[super viewDidLoad];
_statusLabel.text = statusVar;
}
SecondViewController.m (with AppDelegate.h imported into .h)
- (IBAction)updateStatusPressed:(id)sender {
statusVar = [NSString stringWithFormat:@"Update"];
}
However am not sure how to get the label to refresh with this updated data.