I'm a beginner iPhone developer.
I have 2 classes. TestViewController
(this is linked withe view in the storyboard) and ViewController
.
I am trying to call a method([tc refresh:val];
) in TestViewController
with val
as the parameter from ViewController
class. I can see from the logs that val
reaches the TestViewController
, but for some reason, the label does not update and I do not get the current text of the label also which I have set in the view. It gives null
value. Please see the code and log i get and advice me how can I get the label updated by calling a method from VC
to TVC
.
TestViewController.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface TestViewController : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *lblDisp;
- (IBAction)chngText:(id)sender;
- (void)refresh:(NSString *)val;
@end
TestViewController.m
#import "TestViewController.h"
#import "ViewController.h"
@implementation TestViewController
@synthesize lblDisp;
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"TEST VC LOADED");
NSLog(@"TEXT CUrret VALUE SUPERVIEW %@",lblDisp.text);
}
- (IBAction)chngText:(id)sender {
ViewController *dd=[[ViewController alloc]init];
[dd display];
}
-(void)refresh:(NSString *)val{
NSLog(@"Value of Val = %@",val);
NSLog(@"TEXT CUrret VALUE %@",lblDisp.text);
lblDisp.text=val;
}
@end
ViewController.h
#import <UIKit/UIKit.h>
#import "TestViewController.h"
@interface ViewController : UIViewController
-(void)display;
@end
ViewController.m
#import "ViewController.h"
#import "TestViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"VC LOADED");
}
-(void)display{
NSLog(@"Reached VC");
NSString *val=@"1";
TestViewController *tc=[[TestViewController alloc]init];
[tc refresh:val];
}
@end
Log
2013-07-24 03:13:36.413 Simple test[38477:11303] TEST VC LOADED
2013-07-24 03:13:36.415 Simple test[38477:11303] TEXT CUrret VALUE SUPERVIEW sdfgdfgd
2013-07-24 03:13:37.909 Simple test[38477:11303] Reached VC
2013-07-24 03:13:37.910 Simple test[38477:11303] Value of Val = 1
2013-07-24 03:13:37.911 Simple test[38477:11303] TEXT CUrret VALUE (null)