Thursday, 8 August 2013

Updating UILabel in Child View 1 after Global Variable Update in Child View 2

Updating UILabel in Child View 1 after Global Variable Update in Child View 2

I have made a simple app to test this and cannot figure it out. I have an
iPad storyboard where I have put two container views as shown below. I
have a label in one view and a button in another. My button will increment
the label, 1 number at a time.
My problem is not passing the value or incrementing, but getting the view
to load the new value. Each container has its own ViewController
Some code below, although very sparse as Ive written a bunch and deleted
as it didn't work. Please help with the correct format. I would like to
keep this general format, updating global variable within button and it
updating the label.
LabelViewController.h
#import <UIKit/UIKit.h>
@interface LabelViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *checkLabel;
-(void)loadLabel;
@end



LabelViewController.m
#import "LabelViewController.h"
#import "ParentViewController.h"
@interface LabelViewController ()
@end
@implementation LabelViewController
@synthesize checkLabel;
-(void)loadLabel{
checkLabel.text = [NSString stringWithFormat:@"%d",value];
[self.view setNeedsDisplay];
}
- (void)viewDidLoad
{
[self loadLabel];
[super viewDidLoad];
}



ButtonViewController.h
#import <UIKit/UIKit.h>
@interface ButtonViewController : UIViewController
- (IBAction)checkButton:(id)sender;
@end



ButtonViewController.m
#import "ButtonViewController.h"
#import "ParentViewController.h"
#import "LabelViewController.h"
@interface ButtonViewController ()
@end
@implementation ButtonViewController
- (IBAction)checkButton:(id)sender {
value++;
NSLog(@"%d",value);
LabelViewController *fnc = [[LabelViewController alloc] init];
[fnc loadLabel];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
Picture at: http://farm4.staticflickr.com/3822/9469907420_746db25b23_b.jpg

No comments:

Post a Comment