I know this question was already ask several times but i don't get it.
I have 2 classes classA.h & .m and classB.h and .m.
In classA.h i've got a UITextField *myTextfield
.
In classB i import the header of classA and define the class with @class classA
.
I also set classA *classa
.
if i try to get the value of myTextfield like this myString = classA.myTextfield.text; nothing happens
any suggestions what i'm doing wrong here?
i would be so thankfull for an answer becaus without getting this done i can't continue coding :)
开发者_运维问答thanks!
members of Objective-C classes are always private.
In order to access the members of another class, you need to create accessor methods to these properties. The easiest way to do this is is via properties.
Modifiy your classA.h to look like this
@interface classA : UITableViewController
{
IBOutlet UITextField *myTextfield;
...
}
@property(retain, readonly) UITextField * myTextfield;
...
@end
Then modify classA.m to have
@implementation classA
@synthesize myTextfield;
Then when you need to use it in the other class use either
classa.myTextfield.text
Or preferably
[[classa myTextfield] text]
Edit:
Also make sure that myTextField is being set to some value, by hooking it up to some text field in Interface Builder. See a sample Interface Builder tutorial if this is the problem.
精彩评论