I have to pass a string value from one view to a label in other view. But when I do such thing the label value is null. Could not understand where I am going wrong? Here is my code:
In FirstViewController.m
SecondViewController *gp=[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
gp.d.text = [NSString stringWithFormat:@"%@", nam];
[self.view addSubview:gp.view];
[gp release];
In SecondViewController.h
@interface SecondViewController : UIViewController<NSXMLParserDelegate>
{
UILabel *d;
}
@property (nonatomic,retain) IBOutlet UILabel *d;
In SecondViewController.m
@synthesize d;
- (void)viewDidLoad
{
NSString *urlString1 = [NSString stringWithFormat: @"http://192.168.0.108:8732/Design_Time_Addresses/ICloudServices/AppointmentService/json/GetProviders/?cid={%@}", [d text]];
}
But here the value of d is not passed. Why I dont understand. Where am I going wrong?
At the time of passing value to IBOutlet UILablel before adding subview is not allocated (has no memory reference).
So better way is to pass your value after adding subView.
EDIT: better way is to pass string is like this:
Now
Now in viewDidLoad of SecondViewController do this:
Use yourString anywhere as per your requirement.