Setting NSString in one class, calling it in another class
So, I'm trying to set the value of NSString
in one class, and then, call that NSString
in another class and load it into a label.
I have declared the string in Class A
as a nonatomic, retained property. In one method, I set the value of the string.
In Class B
, I import Class A
, alloc, and init Class A
, and then I try to set the label text with:
ClassA *classA = [[ClassA alloc] init];
label.text = classA.string
However, every time I do this, the label remains blank.
So, why 开发者_运维技巧is my property not retaining the value I assign it in the method? The NSString
gets it's value in a tableView didSelectRowAtIndexPath
method.
Thanks!
EDIT I realize I made a mistake while typing the code snippet above, and I left out the property "string" on the object "classA". Forgive me. The comments below were somewhat unnecessary, but thank you for pointing out my mistake. For the record, I know how objects, classes, and properties work.
If it's a property, you should be able to do it by saying label.text = classA.propertyName
(whatever you named your property.)
For example let's say in ClassA
that you created NSString
*stringToOutput
, then in Class B
after instantiating Class A
, you'd state that label.text = classA.stringToOutput
.
Hope that helped!
label.text = classA.somePropertyThatIsAString;
精彩评论