I have two controllers A & B
In B there are one label and one string
In A i have write the below code
B *ObjB =[[B alloc]initWithNibName:@"B" bundle:nil];
ObjB.Mylabel.text=[NSString stringWithString:@"Add New name"];
ObjB.MyString=[NSString stringWithString:@"new string name"];
[self.navigationController pushViewController:ObjB animated:YES];
[ObjB release];
I am only getting the ObjB.MyString value in B , not getting the label text.Can any one help.Thanks in advance.
Well assuming that
MyLabelis aUILabel(sidenote: avoid capitalized names for ivars – in Objc capitalized names are used [by convention] for Classes), the reason that the value is not set is because the view hierarchy of yourBcontroller has not yet been loaded (ie your label isnilat this point). So you got three options:Force the view hierarchy to load & then set your label:
[ObjB loadView]; // Note: Apple says that you never should call this directly (just to illustrate my point)!!Let the system load the hierarchy for you by requesting the view first:
id view = ObjB.view; // This is a bit of a 'hack' actuallyJust add another property in your
Bcontroller, set that and onviewDidLoadset your label’s text (This is the best option in my opinion)