In my viewcontroller, I am creating a label here.
In another viewcontroller I am creating an instance of the first view controller. Here I tried setting the text property of the label. But it doesn't work. I have checked my code over and over and couldn't find any anything missing. I tried creating the label both programmatically as well as using interface builder. Still cant set the text property of the label. Any reason for this?
I create the label in
- (void)viewDidLoad
{
myLabel = [[UILabel alloc]init];
[myLabel setText:@"Hi"];
[myLabel1 setText:@"Hello"];
[myLabel setFrame:CGRectMake(105, 130, 120, 30)];
[myLabel setBackgroundColor:[UIColor clearColor]];
[myLabel setTextColor:[UIColor whiteColor]];
[myLabel setTextAlignment:UITextAlignmentCenter];
[myLabel setAdjustsFontSizeToFitWidth:YES];
[self.view addSubview:myLabel];
[myLabel release];
}
In my first view controller
MySecondViewcontroller *showMyViewcontroller = [[ MySecondViewcontroller alloc]initWithNibName:@"MySecondViewcontroller" bundle:nil];;
showMyViewcontroller.myLabel = @"I cant set the text";
[self.navigationcontroller pushViewController: showMyViewcontroller animated:YES];
[showMyViewcontroller release];
What I am doing wrong here
You try to assign a string to a UILabel, you'll need to assign the string to myLabel.text. Also you'll have to make sure the UILabel is accessible, so make sure it's a property.
Try using an intermediate string to do it, like so:
In FirstViewController:
In your SecondViewController.h
In your SecondViewController.m